{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-02-28T03:50:00.171347Z",
     "start_time": "2025-02-28T03:49:59.946998Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Could not connect to 127.0.0.1: 53312\n",
      "Traceback (most recent call last):\n",
      "  File \"/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_comm.py\", line 465, in start_client\n",
      "    s.connect((host, port))\n",
      "ConnectionRefusedError: [Errno 61] Connection refused\n",
      "Traceback (most recent call last):\n",
      "  File \"/Applications/PyCharm.app/Contents/plugins/python/helpers-pro/jupyter_debug/pydev_jupyter_utils.py\", line 81, in attach_to_debugger\n",
      "    debugger.connect(pydev_localhost.get_localhost(), debugger_port)\n",
      "  File \"/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py\", line 670, in connect\n",
      "    s = start_client(host, port)\n",
      "  File \"/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_comm.py\", line 465, in start_client\n",
      "    s.connect((host, port))\n",
      "ConnectionRefusedError: [Errno 61] Connection refused\n",
      "Failed to connect to target debugger.\n"
     ]
    }
   ],
   "source": [
    "%matplotlib inline\n",
    "import numpy as np\n",
    "import torch\n",
    "import d2l\n",
    "\n",
    "def f(x):  # Objective function\n",
    "    return x ** 2\n",
    "\n",
    "def f_grad(x):  # Gradient (derivative) of the objective function\n",
    "    return 2 * x"
   ]
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "epoch 10, x: 0.060466\n"
     ]
    }
   ],
   "source": [
    "def gd(eta, f_grad):\n",
    "    x = 10.0\n",
    "    results = [x]\n",
    "    for i in range(10):\n",
    "        x -= eta * f_grad(x)\n",
    "        results.append(float(x))\n",
    "    print(f'epoch 10, x: {x:f}')\n",
    "    return results\n",
    "\n",
    "results = gd(0.2, f_grad)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-02-28T02:34:40.803939Z",
     "start_time": "2025-02-28T02:34:40.799553Z"
    }
   },
   "id": "c8f44bdc4b5d0bde",
   "execution_count": 2
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "[10.0,\n 6.0,\n 3.5999999999999996,\n 2.1599999999999997,\n 1.2959999999999998,\n 0.7775999999999998,\n 0.46655999999999986,\n 0.2799359999999999,\n 0.16796159999999993,\n 0.10077695999999996,\n 0.06046617599999997]"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-02-28T02:34:40.810014Z",
     "start_time": "2025-02-28T02:34:40.805266Z"
    }
   },
   "id": "fcbe8d70d7f03d48",
   "execution_count": 3
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "<Figure size 350x250 with 1 Axes>",
      "image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"249.465625pt\" height=\"183.35625pt\" viewBox=\"0 0 249.465625 183.35625\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n   <cc:Work>\n    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n    <dc:date>2025-02-28T10:34:40.943226</dc:date>\n    <dc:format>image/svg+xml</dc:format>\n    <dc:creator>\n     <cc:Agent>\n      <dc:title>Matplotlib v3.10.0, https://matplotlib.org/</dc:title>\n     </cc:Agent>\n    </dc:creator>\n   </cc:Work>\n  </rdf:RDF>\n </metadata>\n <defs>\n  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n  <g id=\"patch_1\">\n   <path d=\"M 0 183.35625 \nL 249.465625 183.35625 \nL 249.465625 0 \nL 0 0 \nz\n\" style=\"fill: #ffffff\"/>\n  </g>\n  <g id=\"axes_1\">\n   <g id=\"patch_2\">\n    <path d=\"M 46.965625 145.8 \nL 242.265625 145.8 \nL 242.265625 7.2 \nL 46.965625 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g id=\"matplotlib.axis_1\">\n    <g id=\"xtick_1\">\n     <g id=\"line2d_1\">\n      <path d=\"M 55.842898 145.8 \nL 55.842898 7.2 \n\" clip-path=\"url(#p44992c969a)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_2\">\n      <defs>\n       <path id=\"mf7f64591d0\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#mf7f64591d0\" x=\"55.842898\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_1\">\n      <!-- −10 -->\n      <g transform=\"translate(45.290554 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-2212\" d=\"M 678 2272 \nL 4684 2272 \nL 4684 1741 \nL 678 1741 \nL 678 2272 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(83.789062 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(147.412109 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_2\">\n     <g id=\"line2d_3\">\n      <path d=\"M 100.229261 145.8 \nL 100.229261 7.2 \n\" clip-path=\"url(#p44992c969a)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_4\">\n      <g>\n       <use xlink:href=\"#mf7f64591d0\" x=\"100.229261\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_2\">\n      <!-- −5 -->\n      <g transform=\"translate(92.858168 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \nL 3169 4666 \nL 3169 4134 \nL 1269 4134 \nL 1269 2991 \nQ 1406 3038 1543 3061 \nQ 1681 3084 1819 3084 \nQ 2600 3084 3056 2656 \nQ 3513 2228 3513 1497 \nQ 3513 744 3044 326 \nQ 2575 -91 1722 -91 \nQ 1428 -91 1123 -41 \nQ 819 9 494 109 \nL 494 744 \nQ 775 591 1075 516 \nQ 1375 441 1709 441 \nQ 2250 441 2565 725 \nQ 2881 1009 2881 1497 \nQ 2881 1984 2565 2268 \nQ 2250 2553 1709 2553 \nQ 1456 2553 1204 2497 \nQ 953 2441 691 2322 \nL 691 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(83.789062 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_3\">\n     <g id=\"line2d_5\">\n      <path d=\"M 144.615625 145.8 \nL 144.615625 7.2 \n\" clip-path=\"url(#p44992c969a)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_6\">\n      <g>\n       <use xlink:href=\"#mf7f64591d0\" x=\"144.615625\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_3\">\n      <!-- 0 -->\n      <g transform=\"translate(141.434375 160.398438) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_4\">\n     <g id=\"line2d_7\">\n      <path d=\"M 189.001989 145.8 \nL 189.001989 7.2 \n\" clip-path=\"url(#p44992c969a)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_8\">\n      <g>\n       <use xlink:href=\"#mf7f64591d0\" x=\"189.001989\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_4\">\n      <!-- 5 -->\n      <g transform=\"translate(185.820739 160.398438) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-35\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_5\">\n     <g id=\"line2d_9\">\n      <path d=\"M 233.388352 145.8 \nL 233.388352 7.2 \n\" clip-path=\"url(#p44992c969a)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_10\">\n      <g>\n       <use xlink:href=\"#mf7f64591d0\" x=\"233.388352\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_5\">\n      <!-- 10 -->\n      <g transform=\"translate(227.025852 160.398438) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_6\">\n     <!-- x -->\n     <g transform=\"translate(141.65625 174.076563) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-78\" d=\"M 3513 3500 \nL 2247 1797 \nL 3578 0 \nL 2900 0 \nL 1881 1375 \nL 863 0 \nL 184 0 \nL 1544 1831 \nL 300 3500 \nL 978 3500 \nL 1906 2253 \nL 2834 3500 \nL 3513 3500 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-78\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_2\">\n    <g id=\"ytick_1\">\n     <g id=\"line2d_11\">\n      <path d=\"M 46.965625 139.5 \nL 242.265625 139.5 \n\" clip-path=\"url(#p44992c969a)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_12\">\n      <defs>\n       <path id=\"m2a77a3feb5\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m2a77a3feb5\" x=\"46.965625\" y=\"139.5\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_7\">\n      <!-- 0 -->\n      <g transform=\"translate(33.603125 143.299219) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_2\">\n     <g id=\"line2d_13\">\n      <path d=\"M 46.965625 114.3 \nL 242.265625 114.3 \n\" clip-path=\"url(#p44992c969a)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_14\">\n      <g>\n       <use xlink:href=\"#m2a77a3feb5\" x=\"46.965625\" y=\"114.3\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_8\">\n      <!-- 20 -->\n      <g transform=\"translate(27.240625 118.099219) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-32\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_3\">\n     <g id=\"line2d_15\">\n      <path d=\"M 46.965625 89.1 \nL 242.265625 89.1 \n\" clip-path=\"url(#p44992c969a)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_16\">\n      <g>\n       <use xlink:href=\"#m2a77a3feb5\" x=\"46.965625\" y=\"89.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_9\">\n      <!-- 40 -->\n      <g transform=\"translate(27.240625 92.899219) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \nL 825 1625 \nL 2419 1625 \nL 2419 4116 \nz\nM 2253 4666 \nL 3047 4666 \nL 3047 1625 \nL 3713 1625 \nL 3713 1100 \nL 3047 1100 \nL 3047 0 \nL 2419 0 \nL 2419 1100 \nL 313 1100 \nL 313 1709 \nL 2253 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-34\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_4\">\n     <g id=\"line2d_17\">\n      <path d=\"M 46.965625 63.9 \nL 242.265625 63.9 \n\" clip-path=\"url(#p44992c969a)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_18\">\n      <g>\n       <use xlink:href=\"#m2a77a3feb5\" x=\"46.965625\" y=\"63.9\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_10\">\n      <!-- 60 -->\n      <g transform=\"translate(27.240625 67.699219) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \nQ 1688 2584 1439 2293 \nQ 1191 2003 1191 1497 \nQ 1191 994 1439 701 \nQ 1688 409 2113 409 \nQ 2538 409 2786 701 \nQ 3034 994 3034 1497 \nQ 3034 2003 2786 2293 \nQ 2538 2584 2113 2584 \nz\nM 3366 4563 \nL 3366 3988 \nQ 3128 4100 2886 4159 \nQ 2644 4219 2406 4219 \nQ 1781 4219 1451 3797 \nQ 1122 3375 1075 2522 \nQ 1259 2794 1537 2939 \nQ 1816 3084 2150 3084 \nQ 2853 3084 3261 2657 \nQ 3669 2231 3669 1497 \nQ 3669 778 3244 343 \nQ 2819 -91 2113 -91 \nQ 1303 -91 875 529 \nQ 447 1150 447 2328 \nQ 447 3434 972 4092 \nQ 1497 4750 2381 4750 \nQ 2619 4750 2861 4703 \nQ 3103 4656 3366 4563 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-36\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_5\">\n     <g id=\"line2d_19\">\n      <path d=\"M 46.965625 38.7 \nL 242.265625 38.7 \n\" clip-path=\"url(#p44992c969a)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_20\">\n      <g>\n       <use xlink:href=\"#m2a77a3feb5\" x=\"46.965625\" y=\"38.7\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_11\">\n      <!-- 80 -->\n      <g transform=\"translate(27.240625 42.499219) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-38\" d=\"M 2034 2216 \nQ 1584 2216 1326 1975 \nQ 1069 1734 1069 1313 \nQ 1069 891 1326 650 \nQ 1584 409 2034 409 \nQ 2484 409 2743 651 \nQ 3003 894 3003 1313 \nQ 3003 1734 2745 1975 \nQ 2488 2216 2034 2216 \nz\nM 1403 2484 \nQ 997 2584 770 2862 \nQ 544 3141 544 3541 \nQ 544 4100 942 4425 \nQ 1341 4750 2034 4750 \nQ 2731 4750 3128 4425 \nQ 3525 4100 3525 3541 \nQ 3525 3141 3298 2862 \nQ 3072 2584 2669 2484 \nQ 3125 2378 3379 2068 \nQ 3634 1759 3634 1313 \nQ 3634 634 3220 271 \nQ 2806 -91 2034 -91 \nQ 1263 -91 848 271 \nQ 434 634 434 1313 \nQ 434 1759 690 2068 \nQ 947 2378 1403 2484 \nz\nM 1172 3481 \nQ 1172 3119 1398 2916 \nQ 1625 2713 2034 2713 \nQ 2441 2713 2670 2916 \nQ 2900 3119 2900 3481 \nQ 2900 3844 2670 4047 \nQ 2441 4250 2034 4250 \nQ 1625 4250 1398 4047 \nQ 1172 3844 1172 3481 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-38\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_6\">\n     <g id=\"line2d_21\">\n      <path d=\"M 46.965625 13.5 \nL 242.265625 13.5 \n\" clip-path=\"url(#p44992c969a)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_22\">\n      <g>\n       <use xlink:href=\"#m2a77a3feb5\" x=\"46.965625\" y=\"13.5\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_12\">\n      <!-- 100 -->\n      <g transform=\"translate(20.878125 17.299219) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(127.246094 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_13\">\n     <!-- f(x) -->\n     <g transform=\"translate(14.798438 85.121094) rotate(-90) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-66\" d=\"M 2375 4863 \nL 2375 4384 \nL 1825 4384 \nQ 1516 4384 1395 4259 \nQ 1275 4134 1275 3809 \nL 1275 3500 \nL 2222 3500 \nL 2222 3053 \nL 1275 3053 \nL 1275 0 \nL 697 0 \nL 697 3053 \nL 147 3053 \nL 147 3500 \nL 697 3500 \nL 697 3744 \nQ 697 4328 969 4595 \nQ 1241 4863 1831 4863 \nL 2375 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-28\" d=\"M 1984 4856 \nQ 1566 4138 1362 3434 \nQ 1159 2731 1159 2009 \nQ 1159 1288 1364 580 \nQ 1569 -128 1984 -844 \nL 1484 -844 \nQ 1016 -109 783 600 \nQ 550 1309 550 2009 \nQ 550 2706 781 3412 \nQ 1013 4119 1484 4856 \nL 1984 4856 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-29\" d=\"M 513 4856 \nL 1013 4856 \nQ 1481 4119 1714 3412 \nQ 1947 2706 1947 2009 \nQ 1947 1309 1714 600 \nQ 1481 -109 1013 -844 \nL 513 -844 \nQ 928 -128 1133 580 \nQ 1338 1288 1338 2009 \nQ 1338 2731 1133 3434 \nQ 928 4138 513 4856 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-66\"/>\n      <use xlink:href=\"#DejaVuSans-28\" transform=\"translate(35.205078 0)\"/>\n      <use xlink:href=\"#DejaVuSans-78\" transform=\"translate(74.21875 0)\"/>\n      <use xlink:href=\"#DejaVuSans-29\" transform=\"translate(133.398438 0)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"line2d_23\">\n    <path d=\"M 55.842898 13.5 \nL 60.459075 26.263287 \nL 64.89772 37.893111 \nL 69.247573 48.679063 \nL 73.508668 58.65827 \nL 77.680989 67.866983 \nL 81.764535 76.340736 \nL 85.670535 83.947104 \nL 89.487765 90.909241 \nL 93.216216 97.259632 \nL 96.855897 103.030055 \nL 100.406807 108.251496 \nL 103.868946 112.954199 \nL 107.242311 117.167639 \nL 110.526898 120.920544 \nL 113.722716 124.240896 \nL 116.82976 127.155905 \nL 119.848034 129.692035 \nL 122.866306 131.93685 \nL 125.795806 133.837055 \nL 128.636533 135.4176 \nL 131.388489 136.702674 \nL 134.140443 137.745576 \nL 136.803625 138.524256 \nL 139.466807 139.076136 \nL 142.129989 139.401216 \nL 144.79317 139.499496 \nL 147.456352 139.370976 \nL 150.119534 139.015656 \nL 152.782716 138.433536 \nL 155.445898 137.624616 \nL 158.197852 136.550466 \nL 160.949807 135.234144 \nL 163.790535 133.621344 \nL 166.631262 131.750496 \nL 169.560761 129.550915 \nL 172.579033 126.997652 \nL 175.597307 124.153073 \nL 178.704352 120.920544 \nL 181.900169 117.273603 \nL 185.184763 113.185025 \nL 188.558128 108.626847 \nL 192.020263 103.570341 \nL 195.571168 97.986027 \nL 199.210853 91.843647 \nL 202.939308 85.112224 \nL 206.756534 77.76 \nL 210.662535 69.754465 \nL 214.65731 61.062347 \nL 218.829622 51.43911 \nL 223.090717 41.036545 \nL 227.440579 29.81839 \nL 231.879215 17.747588 \nL 233.299578 13.751881 \nL 233.299578 13.751881 \n\" clip-path=\"url(#p44992c969a)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n   </g>\n   <g id=\"line2d_24\">\n    <path d=\"M 233.388352 13.5 \nL 197.879261 94.14 \nL 176.573807 123.1704 \nL 163.790534 133.621344 \nL 156.12057 137.383684 \nL 151.518592 138.738126 \nL 148.757405 139.225725 \nL 147.100693 139.401261 \nL 146.106666 139.464454 \nL 145.51025 139.487203 \nL 145.1524 139.495393 \n\" clip-path=\"url(#p44992c969a)\" style=\"fill: none; stroke: #ff7f0e; stroke-width: 1.5; stroke-linecap: square\"/>\n    <defs>\n     <path id=\"me0f07b1c9e\" d=\"M 0 3 \nC 0.795609 3 1.55874 2.683901 2.12132 2.12132 \nC 2.683901 1.55874 3 0.795609 3 0 \nC 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \nC 1.55874 -2.683901 0.795609 -3 0 -3 \nC -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \nC -2.683901 -1.55874 -3 -0.795609 -3 0 \nC -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \nC -1.55874 2.683901 -0.795609 3 0 3 \nz\n\" style=\"stroke: #ff7f0e\"/>\n    </defs>\n    <g clip-path=\"url(#p44992c969a)\">\n     <use xlink:href=\"#me0f07b1c9e\" x=\"233.388352\" y=\"13.5\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#me0f07b1c9e\" x=\"197.879261\" y=\"94.14\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#me0f07b1c9e\" x=\"176.573807\" y=\"123.1704\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#me0f07b1c9e\" x=\"163.790534\" y=\"133.621344\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#me0f07b1c9e\" x=\"156.12057\" y=\"137.383684\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#me0f07b1c9e\" x=\"151.518592\" y=\"138.738126\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#me0f07b1c9e\" x=\"148.757405\" y=\"139.225725\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#me0f07b1c9e\" x=\"147.100693\" y=\"139.401261\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#me0f07b1c9e\" x=\"146.106666\" y=\"139.464454\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#me0f07b1c9e\" x=\"145.51025\" y=\"139.487203\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#me0f07b1c9e\" x=\"145.1524\" y=\"139.495393\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n    </g>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 46.965625 145.8 \nL 46.965625 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_4\">\n    <path d=\"M 242.265625 145.8 \nL 242.265625 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_5\">\n    <path d=\"M 46.965625 145.8 \nL 242.265625 145.8 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_6\">\n    <path d=\"M 46.965625 7.2 \nL 242.265625 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n </g>\n <defs>\n  <clipPath id=\"p44992c969a\">\n   <rect x=\"46.965625\" y=\"7.2\" width=\"195.3\" height=\"138.6\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def show_trace(results, f):\n",
    "    n = max(abs(min(results)), abs(max(results)))\n",
    "    f_line = torch.arange(-n, n, 0.01)\n",
    "    d2l.set_figsize()\n",
    "    d2l.plot([f_line, results], [[f(x) for x in f_line], [\n",
    "        f(x) for x in results]], 'x', 'f(x)', fmts=['-', '-o'])\n",
    "\n",
    "show_trace(results, f)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-02-28T02:34:40.971076Z",
     "start_time": "2025-02-28T02:34:40.813006Z"
    }
   },
   "id": "83a1a9c98ae722a7",
   "execution_count": 4
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "epoch 10, x: 3.486784\n"
     ]
    },
    {
     "data": {
      "text/plain": "<Figure size 350x250 with 1 Axes>",
      "image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"249.465625pt\" height=\"183.35625pt\" viewBox=\"0 0 249.465625 183.35625\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n   <cc:Work>\n    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n    <dc:date>2025-02-28T10:34:41.089652</dc:date>\n    <dc:format>image/svg+xml</dc:format>\n    <dc:creator>\n     <cc:Agent>\n      <dc:title>Matplotlib v3.10.0, https://matplotlib.org/</dc:title>\n     </cc:Agent>\n    </dc:creator>\n   </cc:Work>\n  </rdf:RDF>\n </metadata>\n <defs>\n  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n  <g id=\"patch_1\">\n   <path d=\"M 0 183.35625 \nL 249.465625 183.35625 \nL 249.465625 0 \nL 0 0 \nz\n\" style=\"fill: #ffffff\"/>\n  </g>\n  <g id=\"axes_1\">\n   <g id=\"patch_2\">\n    <path d=\"M 46.965625 145.8 \nL 242.265625 145.8 \nL 242.265625 7.2 \nL 46.965625 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g id=\"matplotlib.axis_1\">\n    <g id=\"xtick_1\">\n     <g id=\"line2d_1\">\n      <path d=\"M 55.842898 145.8 \nL 55.842898 7.2 \n\" clip-path=\"url(#pc6a051f4fb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_2\">\n      <defs>\n       <path id=\"m772c17b301\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m772c17b301\" x=\"55.842898\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_1\">\n      <!-- −10 -->\n      <g transform=\"translate(45.290554 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-2212\" d=\"M 678 2272 \nL 4684 2272 \nL 4684 1741 \nL 678 1741 \nL 678 2272 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(83.789062 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(147.412109 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_2\">\n     <g id=\"line2d_3\">\n      <path d=\"M 100.229261 145.8 \nL 100.229261 7.2 \n\" clip-path=\"url(#pc6a051f4fb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_4\">\n      <g>\n       <use xlink:href=\"#m772c17b301\" x=\"100.229261\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_2\">\n      <!-- −5 -->\n      <g transform=\"translate(92.858168 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \nL 3169 4666 \nL 3169 4134 \nL 1269 4134 \nL 1269 2991 \nQ 1406 3038 1543 3061 \nQ 1681 3084 1819 3084 \nQ 2600 3084 3056 2656 \nQ 3513 2228 3513 1497 \nQ 3513 744 3044 326 \nQ 2575 -91 1722 -91 \nQ 1428 -91 1123 -41 \nQ 819 9 494 109 \nL 494 744 \nQ 775 591 1075 516 \nQ 1375 441 1709 441 \nQ 2250 441 2565 725 \nQ 2881 1009 2881 1497 \nQ 2881 1984 2565 2268 \nQ 2250 2553 1709 2553 \nQ 1456 2553 1204 2497 \nQ 953 2441 691 2322 \nL 691 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(83.789062 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_3\">\n     <g id=\"line2d_5\">\n      <path d=\"M 144.615625 145.8 \nL 144.615625 7.2 \n\" clip-path=\"url(#pc6a051f4fb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_6\">\n      <g>\n       <use xlink:href=\"#m772c17b301\" x=\"144.615625\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_3\">\n      <!-- 0 -->\n      <g transform=\"translate(141.434375 160.398438) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_4\">\n     <g id=\"line2d_7\">\n      <path d=\"M 189.001989 145.8 \nL 189.001989 7.2 \n\" clip-path=\"url(#pc6a051f4fb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_8\">\n      <g>\n       <use xlink:href=\"#m772c17b301\" x=\"189.001989\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_4\">\n      <!-- 5 -->\n      <g transform=\"translate(185.820739 160.398438) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-35\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_5\">\n     <g id=\"line2d_9\">\n      <path d=\"M 233.388352 145.8 \nL 233.388352 7.2 \n\" clip-path=\"url(#pc6a051f4fb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_10\">\n      <g>\n       <use xlink:href=\"#m772c17b301\" x=\"233.388352\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_5\">\n      <!-- 10 -->\n      <g transform=\"translate(227.025852 160.398438) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_6\">\n     <!-- x -->\n     <g transform=\"translate(141.65625 174.076563) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-78\" d=\"M 3513 3500 \nL 2247 1797 \nL 3578 0 \nL 2900 0 \nL 1881 1375 \nL 863 0 \nL 184 0 \nL 1544 1831 \nL 300 3500 \nL 978 3500 \nL 1906 2253 \nL 2834 3500 \nL 3513 3500 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-78\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_2\">\n    <g id=\"ytick_1\">\n     <g id=\"line2d_11\">\n      <path d=\"M 46.965625 139.5 \nL 242.265625 139.5 \n\" clip-path=\"url(#pc6a051f4fb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_12\">\n      <defs>\n       <path id=\"md1ff495def\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#md1ff495def\" x=\"46.965625\" y=\"139.5\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_7\">\n      <!-- 0 -->\n      <g transform=\"translate(33.603125 143.299219) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_2\">\n     <g id=\"line2d_13\">\n      <path d=\"M 46.965625 114.3 \nL 242.265625 114.3 \n\" clip-path=\"url(#pc6a051f4fb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_14\">\n      <g>\n       <use xlink:href=\"#md1ff495def\" x=\"46.965625\" y=\"114.3\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_8\">\n      <!-- 20 -->\n      <g transform=\"translate(27.240625 118.099219) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-32\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_3\">\n     <g id=\"line2d_15\">\n      <path d=\"M 46.965625 89.1 \nL 242.265625 89.1 \n\" clip-path=\"url(#pc6a051f4fb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_16\">\n      <g>\n       <use xlink:href=\"#md1ff495def\" x=\"46.965625\" y=\"89.1\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_9\">\n      <!-- 40 -->\n      <g transform=\"translate(27.240625 92.899219) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \nL 825 1625 \nL 2419 1625 \nL 2419 4116 \nz\nM 2253 4666 \nL 3047 4666 \nL 3047 1625 \nL 3713 1625 \nL 3713 1100 \nL 3047 1100 \nL 3047 0 \nL 2419 0 \nL 2419 1100 \nL 313 1100 \nL 313 1709 \nL 2253 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-34\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_4\">\n     <g id=\"line2d_17\">\n      <path d=\"M 46.965625 63.9 \nL 242.265625 63.9 \n\" clip-path=\"url(#pc6a051f4fb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_18\">\n      <g>\n       <use xlink:href=\"#md1ff495def\" x=\"46.965625\" y=\"63.9\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_10\">\n      <!-- 60 -->\n      <g transform=\"translate(27.240625 67.699219) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \nQ 1688 2584 1439 2293 \nQ 1191 2003 1191 1497 \nQ 1191 994 1439 701 \nQ 1688 409 2113 409 \nQ 2538 409 2786 701 \nQ 3034 994 3034 1497 \nQ 3034 2003 2786 2293 \nQ 2538 2584 2113 2584 \nz\nM 3366 4563 \nL 3366 3988 \nQ 3128 4100 2886 4159 \nQ 2644 4219 2406 4219 \nQ 1781 4219 1451 3797 \nQ 1122 3375 1075 2522 \nQ 1259 2794 1537 2939 \nQ 1816 3084 2150 3084 \nQ 2853 3084 3261 2657 \nQ 3669 2231 3669 1497 \nQ 3669 778 3244 343 \nQ 2819 -91 2113 -91 \nQ 1303 -91 875 529 \nQ 447 1150 447 2328 \nQ 447 3434 972 4092 \nQ 1497 4750 2381 4750 \nQ 2619 4750 2861 4703 \nQ 3103 4656 3366 4563 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-36\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_5\">\n     <g id=\"line2d_19\">\n      <path d=\"M 46.965625 38.7 \nL 242.265625 38.7 \n\" clip-path=\"url(#pc6a051f4fb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_20\">\n      <g>\n       <use xlink:href=\"#md1ff495def\" x=\"46.965625\" y=\"38.7\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_11\">\n      <!-- 80 -->\n      <g transform=\"translate(27.240625 42.499219) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-38\" d=\"M 2034 2216 \nQ 1584 2216 1326 1975 \nQ 1069 1734 1069 1313 \nQ 1069 891 1326 650 \nQ 1584 409 2034 409 \nQ 2484 409 2743 651 \nQ 3003 894 3003 1313 \nQ 3003 1734 2745 1975 \nQ 2488 2216 2034 2216 \nz\nM 1403 2484 \nQ 997 2584 770 2862 \nQ 544 3141 544 3541 \nQ 544 4100 942 4425 \nQ 1341 4750 2034 4750 \nQ 2731 4750 3128 4425 \nQ 3525 4100 3525 3541 \nQ 3525 3141 3298 2862 \nQ 3072 2584 2669 2484 \nQ 3125 2378 3379 2068 \nQ 3634 1759 3634 1313 \nQ 3634 634 3220 271 \nQ 2806 -91 2034 -91 \nQ 1263 -91 848 271 \nQ 434 634 434 1313 \nQ 434 1759 690 2068 \nQ 947 2378 1403 2484 \nz\nM 1172 3481 \nQ 1172 3119 1398 2916 \nQ 1625 2713 2034 2713 \nQ 2441 2713 2670 2916 \nQ 2900 3119 2900 3481 \nQ 2900 3844 2670 4047 \nQ 2441 4250 2034 4250 \nQ 1625 4250 1398 4047 \nQ 1172 3844 1172 3481 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-38\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_6\">\n     <g id=\"line2d_21\">\n      <path d=\"M 46.965625 13.5 \nL 242.265625 13.5 \n\" clip-path=\"url(#pc6a051f4fb)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_22\">\n      <g>\n       <use xlink:href=\"#md1ff495def\" x=\"46.965625\" y=\"13.5\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_12\">\n      <!-- 100 -->\n      <g transform=\"translate(20.878125 17.299219) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(127.246094 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_13\">\n     <!-- f(x) -->\n     <g transform=\"translate(14.798438 85.121094) rotate(-90) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-66\" d=\"M 2375 4863 \nL 2375 4384 \nL 1825 4384 \nQ 1516 4384 1395 4259 \nQ 1275 4134 1275 3809 \nL 1275 3500 \nL 2222 3500 \nL 2222 3053 \nL 1275 3053 \nL 1275 0 \nL 697 0 \nL 697 3053 \nL 147 3053 \nL 147 3500 \nL 697 3500 \nL 697 3744 \nQ 697 4328 969 4595 \nQ 1241 4863 1831 4863 \nL 2375 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-28\" d=\"M 1984 4856 \nQ 1566 4138 1362 3434 \nQ 1159 2731 1159 2009 \nQ 1159 1288 1364 580 \nQ 1569 -128 1984 -844 \nL 1484 -844 \nQ 1016 -109 783 600 \nQ 550 1309 550 2009 \nQ 550 2706 781 3412 \nQ 1013 4119 1484 4856 \nL 1984 4856 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-29\" d=\"M 513 4856 \nL 1013 4856 \nQ 1481 4119 1714 3412 \nQ 1947 2706 1947 2009 \nQ 1947 1309 1714 600 \nQ 1481 -109 1013 -844 \nL 513 -844 \nQ 928 -128 1133 580 \nQ 1338 1288 1338 2009 \nQ 1338 2731 1133 3434 \nQ 928 4138 513 4856 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-66\"/>\n      <use xlink:href=\"#DejaVuSans-28\" transform=\"translate(35.205078 0)\"/>\n      <use xlink:href=\"#DejaVuSans-78\" transform=\"translate(74.21875 0)\"/>\n      <use xlink:href=\"#DejaVuSans-29\" transform=\"translate(133.398438 0)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"line2d_23\">\n    <path d=\"M 55.842898 13.5 \nL 60.459075 26.263287 \nL 64.89772 37.893111 \nL 69.247573 48.679063 \nL 73.508668 58.65827 \nL 77.680989 67.866983 \nL 81.764535 76.340736 \nL 85.670535 83.947104 \nL 89.487765 90.909241 \nL 93.216216 97.259632 \nL 96.855897 103.030055 \nL 100.406807 108.251496 \nL 103.868946 112.954199 \nL 107.242311 117.167639 \nL 110.526898 120.920544 \nL 113.722716 124.240896 \nL 116.82976 127.155905 \nL 119.848034 129.692035 \nL 122.866306 131.93685 \nL 125.795806 133.837055 \nL 128.636533 135.4176 \nL 131.388489 136.702674 \nL 134.140443 137.745576 \nL 136.803625 138.524256 \nL 139.466807 139.076136 \nL 142.129989 139.401216 \nL 144.79317 139.499496 \nL 147.456352 139.370976 \nL 150.119534 139.015656 \nL 152.782716 138.433536 \nL 155.445898 137.624616 \nL 158.197852 136.550466 \nL 160.949807 135.234144 \nL 163.790535 133.621344 \nL 166.631262 131.750496 \nL 169.560761 129.550915 \nL 172.579033 126.997652 \nL 175.597307 124.153073 \nL 178.704352 120.920544 \nL 181.900169 117.273603 \nL 185.184763 113.185025 \nL 188.558128 108.626847 \nL 192.020263 103.570341 \nL 195.571168 97.986027 \nL 199.210853 91.843647 \nL 202.939308 85.112224 \nL 206.756534 77.76 \nL 210.662535 69.754465 \nL 214.65731 61.062347 \nL 218.829622 51.43911 \nL 223.090717 41.036545 \nL 227.440579 29.81839 \nL 231.879215 17.747588 \nL 233.299578 13.751881 \nL 233.299578 13.751881 \n\" clip-path=\"url(#pc6a051f4fb)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n   </g>\n   <g id=\"line2d_24\">\n    <path d=\"M 233.388352 13.5 \nL 224.51108 37.44 \nL 216.521534 56.8314 \nL 209.330943 72.538434 \nL 202.859411 85.261132 \nL 197.035033 95.566517 \nL 191.793092 103.913878 \nL 187.075345 110.675242 \nL 182.829373 116.151946 \nL 179.007998 120.588076 \nL 175.568761 124.181342 \n\" clip-path=\"url(#pc6a051f4fb)\" style=\"fill: none; stroke: #ff7f0e; stroke-width: 1.5; stroke-linecap: square\"/>\n    <defs>\n     <path id=\"m7e9df44725\" d=\"M 0 3 \nC 0.795609 3 1.55874 2.683901 2.12132 2.12132 \nC 2.683901 1.55874 3 0.795609 3 0 \nC 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \nC 1.55874 -2.683901 0.795609 -3 0 -3 \nC -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \nC -2.683901 -1.55874 -3 -0.795609 -3 0 \nC -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \nC -1.55874 2.683901 -0.795609 3 0 3 \nz\n\" style=\"stroke: #ff7f0e\"/>\n    </defs>\n    <g clip-path=\"url(#pc6a051f4fb)\">\n     <use xlink:href=\"#m7e9df44725\" x=\"233.388352\" y=\"13.5\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m7e9df44725\" x=\"224.51108\" y=\"37.44\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m7e9df44725\" x=\"216.521534\" y=\"56.8314\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m7e9df44725\" x=\"209.330943\" y=\"72.538434\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m7e9df44725\" x=\"202.859411\" y=\"85.261132\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m7e9df44725\" x=\"197.035033\" y=\"95.566517\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m7e9df44725\" x=\"191.793092\" y=\"103.913878\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m7e9df44725\" x=\"187.075345\" y=\"110.675242\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m7e9df44725\" x=\"182.829373\" y=\"116.151946\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m7e9df44725\" x=\"179.007998\" y=\"120.588076\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m7e9df44725\" x=\"175.568761\" y=\"124.181342\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n    </g>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 46.965625 145.8 \nL 46.965625 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_4\">\n    <path d=\"M 242.265625 145.8 \nL 242.265625 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_5\">\n    <path d=\"M 46.965625 145.8 \nL 242.265625 145.8 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_6\">\n    <path d=\"M 46.965625 7.2 \nL 242.265625 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n </g>\n <defs>\n  <clipPath id=\"pc6a051f4fb\">\n   <rect x=\"46.965625\" y=\"7.2\" width=\"195.3\" height=\"138.6\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "show_trace(gd(0.05, f_grad), f)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-02-28T02:34:41.117871Z",
     "start_time": "2025-02-28T02:34:40.973243Z"
    }
   },
   "id": "84664f2e30d8a59c",
   "execution_count": 5
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "epoch 10, x: 61.917364\n"
     ]
    },
    {
     "data": {
      "text/plain": "<Figure size 350x250 with 1 Axes>",
      "image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"255.828125pt\" height=\"186.319088pt\" viewBox=\"0 0 255.828125 186.319088\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n   <cc:Work>\n    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n    <dc:date>2025-02-28T10:34:41.418280</dc:date>\n    <dc:format>image/svg+xml</dc:format>\n    <dc:creator>\n     <cc:Agent>\n      <dc:title>Matplotlib v3.10.0, https://matplotlib.org/</dc:title>\n     </cc:Agent>\n    </dc:creator>\n   </cc:Work>\n  </rdf:RDF>\n </metadata>\n <defs>\n  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n  <g id=\"patch_1\">\n   <path d=\"M 0 186.319088 \nL 255.828125 186.319088 \nL 255.828125 0 \nL 0 0 \nz\n\" style=\"fill: #ffffff\"/>\n  </g>\n  <g id=\"axes_1\">\n   <g id=\"patch_2\">\n    <path d=\"M 53.328125 148.762838 \nL 248.628125 148.762838 \nL 248.628125 10.162838 \nL 53.328125 10.162838 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g id=\"matplotlib.axis_1\">\n    <g id=\"xtick_1\">\n     <g id=\"line2d_1\">\n      <path d=\"M 79.291672 148.762838 \nL 79.291672 10.162838 \n\" clip-path=\"url(#p3e17127311)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_2\">\n      <defs>\n       <path id=\"m006e74167a\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m006e74167a\" x=\"79.291672\" y=\"148.762838\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_1\">\n      <!-- −50 -->\n      <g transform=\"translate(68.739328 163.361276) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-2212\" d=\"M 678 2272 \nL 4684 2272 \nL 4684 1741 \nL 678 1741 \nL 678 2272 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \nL 3169 4666 \nL 3169 4134 \nL 1269 4134 \nL 1269 2991 \nQ 1406 3038 1543 3061 \nQ 1681 3084 1819 3084 \nQ 2600 3084 3056 2656 \nQ 3513 2228 3513 1497 \nQ 3513 744 3044 326 \nQ 2575 -91 1722 -91 \nQ 1428 -91 1123 -41 \nQ 819 9 494 109 \nL 494 744 \nQ 775 591 1075 516 \nQ 1375 441 1709 441 \nQ 2250 441 2565 725 \nQ 2881 1009 2881 1497 \nQ 2881 1984 2565 2268 \nQ 2250 2553 1709 2553 \nQ 1456 2553 1204 2497 \nQ 953 2441 691 2322 \nL 691 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(83.789062 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(147.412109 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_2\">\n     <g id=\"line2d_3\">\n      <path d=\"M 115.134899 148.762838 \nL 115.134899 10.162838 \n\" clip-path=\"url(#p3e17127311)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_4\">\n      <g>\n       <use xlink:href=\"#m006e74167a\" x=\"115.134899\" y=\"148.762838\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_2\">\n      <!-- −25 -->\n      <g transform=\"translate(104.582555 163.361276) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-32\" transform=\"translate(83.789062 0)\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(147.412109 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_3\">\n     <g id=\"line2d_5\">\n      <path d=\"M 150.978126 148.762838 \nL 150.978126 10.162838 \n\" clip-path=\"url(#p3e17127311)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_6\">\n      <g>\n       <use xlink:href=\"#m006e74167a\" x=\"150.978126\" y=\"148.762838\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_3\">\n      <!-- 0 -->\n      <g transform=\"translate(147.796876 163.361276) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_4\">\n     <g id=\"line2d_7\">\n      <path d=\"M 186.821353 148.762838 \nL 186.821353 10.162838 \n\" clip-path=\"url(#p3e17127311)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_8\">\n      <g>\n       <use xlink:href=\"#m006e74167a\" x=\"186.821353\" y=\"148.762838\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_4\">\n      <!-- 25 -->\n      <g transform=\"translate(180.458853 163.361276) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-32\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_5\">\n     <g id=\"line2d_9\">\n      <path d=\"M 222.664581 148.762838 \nL 222.664581 10.162838 \n\" clip-path=\"url(#p3e17127311)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_10\">\n      <g>\n       <use xlink:href=\"#m006e74167a\" x=\"222.664581\" y=\"148.762838\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_5\">\n      <!-- 50 -->\n      <g transform=\"translate(216.302081 163.361276) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-35\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_6\">\n     <!-- x -->\n     <g transform=\"translate(148.01875 177.039401) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-78\" d=\"M 3513 3500 \nL 2247 1797 \nL 3578 0 \nL 2900 0 \nL 1881 1375 \nL 863 0 \nL 184 0 \nL 1544 1831 \nL 300 3500 \nL 978 3500 \nL 1906 2253 \nL 2834 3500 \nL 3513 3500 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-78\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_2\">\n    <g id=\"ytick_1\">\n     <g id=\"line2d_11\">\n      <path d=\"M 53.328125 142.462839 \nL 248.628125 142.462839 \n\" clip-path=\"url(#p3e17127311)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_12\">\n      <defs>\n       <path id=\"m9fcce7a4bd\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m9fcce7a4bd\" x=\"53.328125\" y=\"142.462839\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_7\">\n      <!-- 0 -->\n      <g transform=\"translate(39.965625 146.262057) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_2\">\n     <g id=\"line2d_13\">\n      <path d=\"M 53.328125 109.596934 \nL 248.628125 109.596934 \n\" clip-path=\"url(#p3e17127311)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_14\">\n      <g>\n       <use xlink:href=\"#m9fcce7a4bd\" x=\"53.328125\" y=\"109.596934\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_8\">\n      <!-- 1000 -->\n      <g transform=\"translate(20.878125 113.396152) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(127.246094 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(190.869141 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_3\">\n     <g id=\"line2d_15\">\n      <path d=\"M 53.328125 76.731029 \nL 248.628125 76.731029 \n\" clip-path=\"url(#p3e17127311)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_16\">\n      <g>\n       <use xlink:href=\"#m9fcce7a4bd\" x=\"53.328125\" y=\"76.731029\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_9\">\n      <!-- 2000 -->\n      <g transform=\"translate(20.878125 80.530247) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-32\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(127.246094 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(190.869141 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_4\">\n     <g id=\"line2d_17\">\n      <path d=\"M 53.328125 43.865124 \nL 248.628125 43.865124 \n\" clip-path=\"url(#p3e17127311)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_18\">\n      <g>\n       <use xlink:href=\"#m9fcce7a4bd\" x=\"53.328125\" y=\"43.865124\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_10\">\n      <!-- 3000 -->\n      <g transform=\"translate(20.878125 47.664342) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \nQ 3050 2419 3304 2112 \nQ 3559 1806 3559 1356 \nQ 3559 666 3084 287 \nQ 2609 -91 1734 -91 \nQ 1441 -91 1130 -33 \nQ 819 25 488 141 \nL 488 750 \nQ 750 597 1062 519 \nQ 1375 441 1716 441 \nQ 2309 441 2620 675 \nQ 2931 909 2931 1356 \nQ 2931 1769 2642 2001 \nQ 2353 2234 1838 2234 \nL 1294 2234 \nL 1294 2753 \nL 1863 2753 \nQ 2328 2753 2575 2939 \nQ 2822 3125 2822 3475 \nQ 2822 3834 2567 4026 \nQ 2313 4219 1838 4219 \nQ 1578 4219 1281 4162 \nQ 984 4106 628 3988 \nL 628 4550 \nQ 988 4650 1302 4700 \nQ 1616 4750 1894 4750 \nQ 2613 4750 3031 4423 \nQ 3450 4097 3450 3541 \nQ 3450 3153 3228 2886 \nQ 3006 2619 2597 2516 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-33\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(127.246094 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(190.869141 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_5\">\n     <g id=\"line2d_19\">\n      <path d=\"M 53.328125 10.999219 \nL 248.628125 10.999219 \n\" clip-path=\"url(#p3e17127311)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_20\">\n      <g>\n       <use xlink:href=\"#m9fcce7a4bd\" x=\"53.328125\" y=\"10.999219\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_11\">\n      <!-- 4000 -->\n      <g transform=\"translate(20.878125 14.798437) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \nL 825 1625 \nL 2419 1625 \nL 2419 4116 \nz\nM 2253 4666 \nL 3047 4666 \nL 3047 1625 \nL 3713 1625 \nL 3713 1100 \nL 3047 1100 \nL 3047 0 \nL 2419 0 \nL 2419 1100 \nL 313 1100 \nL 313 1709 \nL 2253 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-34\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(127.246094 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(190.869141 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_12\">\n     <!-- f(x) -->\n     <g transform=\"translate(14.798437 88.083932) rotate(-90) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-66\" d=\"M 2375 4863 \nL 2375 4384 \nL 1825 4384 \nQ 1516 4384 1395 4259 \nQ 1275 4134 1275 3809 \nL 1275 3500 \nL 2222 3500 \nL 2222 3053 \nL 1275 3053 \nL 1275 0 \nL 697 0 \nL 697 3053 \nL 147 3053 \nL 147 3500 \nL 697 3500 \nL 697 3744 \nQ 697 4328 969 4595 \nQ 1241 4863 1831 4863 \nL 2375 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-28\" d=\"M 1984 4856 \nQ 1566 4138 1362 3434 \nQ 1159 2731 1159 2009 \nQ 1159 1288 1364 580 \nQ 1569 -128 1984 -844 \nL 1484 -844 \nQ 1016 -109 783 600 \nQ 550 1309 550 2009 \nQ 550 2706 781 3412 \nQ 1013 4119 1484 4856 \nL 1984 4856 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-29\" d=\"M 513 4856 \nL 1013 4856 \nQ 1481 4119 1714 3412 \nQ 1947 2706 1947 2009 \nQ 1947 1309 1714 600 \nQ 1481 -109 1013 -844 \nL 513 -844 \nQ 928 -128 1133 580 \nQ 1338 1288 1338 2009 \nQ 1338 2731 1133 3434 \nQ 928 4138 513 4856 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-66\"/>\n      <use xlink:href=\"#DejaVuSans-28\" transform=\"translate(35.205078 0)\"/>\n      <use xlink:href=\"#DejaVuSans-78\" transform=\"translate(74.21875 0)\"/>\n      <use xlink:href=\"#DejaVuSans-29\" transform=\"translate(133.398438 0)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"line2d_21\">\n    <path d=\"M 62.205398 16.462838 \nL 66.778997 29.11151 \nL 71.237895 40.79903 \nL 75.596433 51.609024 \nL 79.854605 61.583441 \nL 84.012416 70.763299 \nL 88.055531 79.159788 \nL 92.012627 86.871468 \nL 95.869361 93.905735 \nL 99.62573 100.29971 \nL 103.281738 106.089566 \nL 106.837388 111.310506 \nL 110.307013 116.015406 \nL 113.676274 120.2158 \nL 116.959515 123.959735 \nL 120.15673 127.274299 \nL 123.28226 130.198579 \nL 126.321764 132.742768 \nL 129.289584 134.941899 \nL 132.200055 136.824991 \nL 135.053176 138.408056 \nL 137.848947 139.706792 \nL 140.58737 140.736581 \nL 143.297117 141.519543 \nL 145.978191 142.063133 \nL 148.63059 142.374726 \nL 151.268651 142.461489 \nL 153.906712 142.32571 \nL 156.544774 141.96739 \nL 159.197173 141.382763 \nL 161.878246 140.563187 \nL 164.587994 139.501288 \nL 167.340754 138.182112 \nL 170.136526 136.594302 \nL 172.989646 134.716233 \nL 175.900119 132.532206 \nL 178.882275 130.013423 \nL 181.936117 127.139375 \nL 185.061647 123.889059 \nL 188.273199 120.223887 \nL 191.570775 116.117354 \nL 194.940039 111.562407 \nL 198.409666 106.492389 \nL 201.965314 100.89729 \nL 205.606982 94.747763 \nL 209.349015 87.986987 \nL 213.177075 80.607456 \nL 217.105489 72.547286 \nL 221.13427 63.768623 \nL 225.263406 54.232704 \nL 229.478573 43.93575 \nL 233.82277 32.729078 \nL 238.267334 20.638935 \nL 239.744073 16.482088 \nL 239.744073 16.482088 \n\" clip-path=\"url(#p3e17127311)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n   </g>\n   <g id=\"line2d_22\">\n    <path d=\"M 165.315417 139.176248 \nL 133.773377 137.730148 \nL 171.623825 135.647765 \nL 126.203288 132.649132 \nL 180.707933 128.331101 \nL 115.302359 122.113137 \nL 193.789047 113.159268 \nL 99.605021 100.265696 \nL 212.625853 81.698954 \nL 77.000855 54.962844 \nL 239.750852 16.462847 \n\" clip-path=\"url(#p3e17127311)\" style=\"fill: none; stroke: #ff7f0e; stroke-width: 1.5; stroke-linecap: square\"/>\n    <defs>\n     <path id=\"mb0d7975306\" d=\"M 0 3 \nC 0.795609 3 1.55874 2.683901 2.12132 2.12132 \nC 2.683901 1.55874 3 0.795609 3 0 \nC 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \nC 1.55874 -2.683901 0.795609 -3 0 -3 \nC -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \nC -2.683901 -1.55874 -3 -0.795609 -3 0 \nC -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \nC -1.55874 2.683901 -0.795609 3 0 3 \nz\n\" style=\"stroke: #ff7f0e\"/>\n    </defs>\n    <g clip-path=\"url(#p3e17127311)\">\n     <use xlink:href=\"#mb0d7975306\" x=\"165.315417\" y=\"139.176248\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mb0d7975306\" x=\"133.773377\" y=\"137.730148\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mb0d7975306\" x=\"171.623825\" y=\"135.647765\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mb0d7975306\" x=\"126.203288\" y=\"132.649132\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mb0d7975306\" x=\"180.707933\" y=\"128.331101\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mb0d7975306\" x=\"115.302359\" y=\"122.113137\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mb0d7975306\" x=\"193.789047\" y=\"113.159268\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mb0d7975306\" x=\"99.605021\" y=\"100.265696\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mb0d7975306\" x=\"212.625853\" y=\"81.698954\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mb0d7975306\" x=\"77.000855\" y=\"54.962844\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mb0d7975306\" x=\"239.750852\" y=\"16.462847\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n    </g>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 53.328125 148.762838 \nL 53.328125 10.162838 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_4\">\n    <path d=\"M 248.628125 148.762838 \nL 248.628125 10.162838 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_5\">\n    <path d=\"M 53.328125 148.762838 \nL 248.628125 148.762838 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_6\">\n    <path d=\"M 53.328125 10.162838 \nL 248.628125 10.162838 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n </g>\n <defs>\n  <clipPath id=\"p3e17127311\">\n   <rect x=\"53.328125\" y=\"10.162838\" width=\"195.3\" height=\"138.6\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "diverges = gd(1.1, f_grad)\n",
    "show_trace(diverges, f)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-02-28T02:34:41.445128Z",
     "start_time": "2025-02-28T02:34:41.119547Z"
    }
   },
   "id": "47eaba75065601fd",
   "execution_count": 6
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "[10.0,\n -12.0,\n 14.400000000000002,\n -17.280000000000005,\n 20.736000000000008,\n -24.883200000000013,\n 29.859840000000023,\n -35.83180800000004,\n 42.998169600000054,\n -51.59780352000007,\n 61.917364224000096]"
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diverges"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-02-28T02:34:41.451109Z",
     "start_time": "2025-02-28T02:34:41.447231Z"
    }
   },
   "id": "6a45d3fe5d844268",
   "execution_count": 7
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "epoch 10, x: -1.528166\n"
     ]
    },
    {
     "data": {
      "text/plain": "<Figure size 350x250 with 1 Axes>",
      "image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"245.120313pt\" height=\"183.35625pt\" viewBox=\"0 0 245.120313 183.35625\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n   <cc:Work>\n    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n    <dc:date>2025-02-28T10:34:41.567477</dc:date>\n    <dc:format>image/svg+xml</dc:format>\n    <dc:creator>\n     <cc:Agent>\n      <dc:title>Matplotlib v3.10.0, https://matplotlib.org/</dc:title>\n     </cc:Agent>\n    </dc:creator>\n   </cc:Work>\n  </rdf:RDF>\n </metadata>\n <defs>\n  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n  <g id=\"patch_1\">\n   <path d=\"M 0 183.35625 \nL 245.120313 183.35625 \nL 245.120313 0 \nL 0 0 \nz\n\" style=\"fill: #ffffff\"/>\n  </g>\n  <g id=\"axes_1\">\n   <g id=\"patch_2\">\n    <path d=\"M 42.620312 145.8 \nL 237.920313 145.8 \nL 237.920313 7.2 \nL 42.620312 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g id=\"matplotlib.axis_1\">\n    <g id=\"xtick_1\">\n     <g id=\"line2d_1\">\n      <path d=\"M 51.497585 145.8 \nL 51.497585 7.2 \n\" clip-path=\"url(#p37e6019735)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_2\">\n      <defs>\n       <path id=\"m761695755a\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m761695755a\" x=\"51.497585\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_1\">\n      <!-- −10 -->\n      <g transform=\"translate(40.945241 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-2212\" d=\"M 678 2272 \nL 4684 2272 \nL 4684 1741 \nL 678 1741 \nL 678 2272 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(83.789062 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(147.412109 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_2\">\n     <g id=\"line2d_3\">\n      <path d=\"M 95.883949 145.8 \nL 95.883949 7.2 \n\" clip-path=\"url(#p37e6019735)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_4\">\n      <g>\n       <use xlink:href=\"#m761695755a\" x=\"95.883949\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_2\">\n      <!-- −5 -->\n      <g transform=\"translate(88.512855 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \nL 3169 4666 \nL 3169 4134 \nL 1269 4134 \nL 1269 2991 \nQ 1406 3038 1543 3061 \nQ 1681 3084 1819 3084 \nQ 2600 3084 3056 2656 \nQ 3513 2228 3513 1497 \nQ 3513 744 3044 326 \nQ 2575 -91 1722 -91 \nQ 1428 -91 1123 -41 \nQ 819 9 494 109 \nL 494 744 \nQ 775 591 1075 516 \nQ 1375 441 1709 441 \nQ 2250 441 2565 725 \nQ 2881 1009 2881 1497 \nQ 2881 1984 2565 2268 \nQ 2250 2553 1709 2553 \nQ 1456 2553 1204 2497 \nQ 953 2441 691 2322 \nL 691 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(83.789062 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_3\">\n     <g id=\"line2d_5\">\n      <path d=\"M 140.270312 145.8 \nL 140.270312 7.2 \n\" clip-path=\"url(#p37e6019735)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_6\">\n      <g>\n       <use xlink:href=\"#m761695755a\" x=\"140.270312\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_3\">\n      <!-- 0 -->\n      <g transform=\"translate(137.089062 160.398438) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_4\">\n     <g id=\"line2d_7\">\n      <path d=\"M 184.656676 145.8 \nL 184.656676 7.2 \n\" clip-path=\"url(#p37e6019735)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_8\">\n      <g>\n       <use xlink:href=\"#m761695755a\" x=\"184.656676\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_4\">\n      <!-- 5 -->\n      <g transform=\"translate(181.475426 160.398438) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-35\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_5\">\n     <g id=\"line2d_9\">\n      <path d=\"M 229.04304 145.8 \nL 229.04304 7.2 \n\" clip-path=\"url(#p37e6019735)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_10\">\n      <g>\n       <use xlink:href=\"#m761695755a\" x=\"229.04304\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_5\">\n      <!-- 10 -->\n      <g transform=\"translate(222.68054 160.398438) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_6\">\n     <!-- x -->\n     <g transform=\"translate(137.310937 174.076563) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-78\" d=\"M 3513 3500 \nL 2247 1797 \nL 3578 0 \nL 2900 0 \nL 1881 1375 \nL 863 0 \nL 184 0 \nL 1544 1831 \nL 300 3500 \nL 978 3500 \nL 1906 2253 \nL 2834 3500 \nL 3513 3500 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-78\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_2\">\n    <g id=\"ytick_1\">\n     <g id=\"line2d_11\">\n      <path d=\"M 42.620312 121.640967 \nL 237.920313 121.640967 \n\" clip-path=\"url(#p37e6019735)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_12\">\n      <defs>\n       <path id=\"m3e23486053\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m3e23486053\" x=\"42.620312\" y=\"121.640967\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_7\">\n      <!-- −5 -->\n      <g transform=\"translate(20.878125 125.440185) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(83.789062 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_2\">\n     <g id=\"line2d_13\">\n      <path d=\"M 42.620312 76.5 \nL 237.920313 76.5 \n\" clip-path=\"url(#p37e6019735)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_14\">\n      <g>\n       <use xlink:href=\"#m3e23486053\" x=\"42.620312\" y=\"76.5\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_8\">\n      <!-- 0 -->\n      <g transform=\"translate(29.257812 80.299219) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_3\">\n     <g id=\"line2d_15\">\n      <path d=\"M 42.620312 31.359033 \nL 237.920313 31.359033 \n\" clip-path=\"url(#p37e6019735)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_16\">\n      <g>\n       <use xlink:href=\"#m3e23486053\" x=\"42.620312\" y=\"31.359033\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_9\">\n      <!-- 5 -->\n      <g transform=\"translate(29.257812 35.158252) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-35\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_10\">\n     <!-- f(x) -->\n     <g transform=\"translate(14.798437 85.121094) rotate(-90) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-66\" d=\"M 2375 4863 \nL 2375 4384 \nL 1825 4384 \nQ 1516 4384 1395 4259 \nQ 1275 4134 1275 3809 \nL 1275 3500 \nL 2222 3500 \nL 2222 3053 \nL 1275 3053 \nL 1275 0 \nL 697 0 \nL 697 3053 \nL 147 3053 \nL 147 3500 \nL 697 3500 \nL 697 3744 \nQ 697 4328 969 4595 \nQ 1241 4863 1831 4863 \nL 2375 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-28\" d=\"M 1984 4856 \nQ 1566 4138 1362 3434 \nQ 1159 2731 1159 2009 \nQ 1159 1288 1364 580 \nQ 1569 -128 1984 -844 \nL 1484 -844 \nQ 1016 -109 783 600 \nQ 550 1309 550 2009 \nQ 550 2706 781 3412 \nQ 1013 4119 1484 4856 \nL 1984 4856 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-29\" d=\"M 513 4856 \nL 1013 4856 \nQ 1481 4119 1714 3412 \nQ 1947 2706 1947 2009 \nQ 1947 1309 1714 600 \nQ 1481 -109 1013 -844 \nL 513 -844 \nQ 928 -128 1133 580 \nQ 1338 1288 1338 2009 \nQ 1338 2731 1133 3434 \nQ 928 4138 513 4856 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-66\"/>\n      <use xlink:href=\"#DejaVuSans-28\" transform=\"translate(35.205078 0)\"/>\n      <use xlink:href=\"#DejaVuSans-78\" transform=\"translate(74.21875 0)\"/>\n      <use xlink:href=\"#DejaVuSans-29\" transform=\"translate(133.398438 0)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"line2d_17\">\n    <path d=\"M 51.497585 76.500001 \nL 54.515859 62.586451 \nL 57.090268 51.752961 \nL 59.309586 43.325861 \nL 61.351355 36.406086 \nL 63.215583 30.83764 \nL 64.991044 26.23239 \nL 66.588956 22.687908 \nL 68.098084 19.871522 \nL 69.518451 17.695347 \nL 70.761268 16.168286 \nL 72.004085 14.990564 \nL 73.158131 14.20593 \nL 74.223403 13.741354 \nL 75.288675 13.521051 \nL 76.353951 13.539197 \nL 77.419222 13.789079 \nL 78.484494 14.263148 \nL 79.63854 15.020002 \nL 80.881362 16.105041 \nL 82.212949 17.560774 \nL 83.722086 19.551486 \nL 85.408769 22.166601 \nL 87.272996 25.480233 \nL 89.40354 29.726556 \nL 91.977948 35.366172 \nL 95.528858 43.724429 \nL 103.163314 61.839574 \nL 106.004039 67.93953 \nL 108.400904 72.589371 \nL 110.53145 76.262462 \nL 112.484448 79.203521 \nL 114.259903 81.497532 \nL 115.946585 83.326808 \nL 117.544495 84.737454 \nL 119.05363 85.779104 \nL 120.473994 86.502463 \nL 121.894359 86.980124 \nL 123.314722 87.218052 \nL 124.735085 87.224602 \nL 126.155449 87.010408 \nL 127.664585 86.55531 \nL 129.262494 85.837474 \nL 131.037949 84.784116 \nL 132.990949 83.357255 \nL 135.29904 81.380765 \nL 138.317313 78.475538 \nL 145.951767 70.98275 \nL 148.259858 69.094507 \nL 150.212858 67.764372 \nL 151.988312 66.814949 \nL 153.586222 66.202363 \nL 155.095359 65.855652 \nL 156.515722 65.750362 \nL 157.936085 65.871412 \nL 159.356448 66.228309 \nL 160.776812 66.828229 \nL 162.197176 67.675905 \nL 163.706313 68.850493 \nL 165.215448 70.306795 \nL 166.813358 72.151568 \nL 168.588811 74.556208 \nL 170.453039 77.464178 \nL 172.494811 81.066691 \nL 174.802902 85.607401 \nL 177.466086 91.359601 \nL 180.83945 99.206191 \nL 190.071814 120.997816 \nL 192.557452 126.154107 \nL 194.687995 130.082447 \nL 196.552223 133.061892 \nL 198.150131 135.22328 \nL 199.659268 136.894963 \nL 200.990859 138.046958 \nL 202.233676 138.831093 \nL 203.387723 139.294721 \nL 204.452994 139.487343 \nL 205.51827 139.446476 \nL 206.583542 139.165611 \nL 207.648814 138.639155 \nL 208.714086 137.862434 \nL 209.868132 136.734267 \nL 211.110949 135.182124 \nL 212.442541 133.128478 \nL 213.862903 130.492079 \nL 215.37204 127.189752 \nL 216.969952 123.138737 \nL 218.745405 117.986217 \nL 220.609632 111.867898 \nL 222.651401 104.384167 \nL 224.959502 95.024237 \nL 227.533903 83.601979 \nL 228.954265 76.925033 \nL 228.954265 76.925033 \n\" clip-path=\"url(#p37e6019735)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n   </g>\n   <g id=\"line2d_18\">\n    <path d=\"M 229.04304 76.499999 \nL 145.376715 71.496411 \nL 129.559104 85.679359 \nL 120.033697 86.304718 \nL 128.344446 86.278274 \nL 120.680218 86.586946 \nL 127.613197 86.574482 \nL 121.143037 86.757761 \nL 127.097544 86.752758 \nL 121.500618 86.872027 \nL 126.70437 86.871151 \n\" clip-path=\"url(#p37e6019735)\" style=\"fill: none; stroke: #ff7f0e; stroke-width: 1.5; stroke-linecap: square\"/>\n    <defs>\n     <path id=\"mf94fa983fd\" d=\"M 0 3 \nC 0.795609 3 1.55874 2.683901 2.12132 2.12132 \nC 2.683901 1.55874 3 0.795609 3 0 \nC 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \nC 1.55874 -2.683901 0.795609 -3 0 -3 \nC -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \nC -2.683901 -1.55874 -3 -0.795609 -3 0 \nC -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \nC -1.55874 2.683901 -0.795609 3 0 3 \nz\n\" style=\"stroke: #ff7f0e\"/>\n    </defs>\n    <g clip-path=\"url(#p37e6019735)\">\n     <use xlink:href=\"#mf94fa983fd\" x=\"229.04304\" y=\"76.499999\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mf94fa983fd\" x=\"145.376715\" y=\"71.496411\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mf94fa983fd\" x=\"129.559104\" y=\"85.679359\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mf94fa983fd\" x=\"120.033697\" y=\"86.304718\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mf94fa983fd\" x=\"128.344446\" y=\"86.278274\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mf94fa983fd\" x=\"120.680218\" y=\"86.586946\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mf94fa983fd\" x=\"127.613197\" y=\"86.574482\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mf94fa983fd\" x=\"121.143037\" y=\"86.757761\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mf94fa983fd\" x=\"127.097544\" y=\"86.752758\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mf94fa983fd\" x=\"121.500618\" y=\"86.872027\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mf94fa983fd\" x=\"126.70437\" y=\"86.871151\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n    </g>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 42.620312 145.8 \nL 42.620312 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_4\">\n    <path d=\"M 237.920313 145.8 \nL 237.920313 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_5\">\n    <path d=\"M 42.620312 145.8 \nL 237.920313 145.8 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_6\">\n    <path d=\"M 42.620312 7.2 \nL 237.920313 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n </g>\n <defs>\n  <clipPath id=\"p37e6019735\">\n   <rect x=\"42.620312\" y=\"7.2\" width=\"195.3\" height=\"138.6\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "c = torch.tensor(0.15 * np.pi)\n",
    "\n",
    "def f(x):  # Objective function\n",
    "    return x * torch.cos(c * x)\n",
    "\n",
    "def f_grad(x):  # Gradient of the objective function\n",
    "    return torch.cos(c * x) - c * x * torch.sin(c * x)\n",
    "\n",
    "gradients = gd(2, f_grad)\n",
    "show_trace(gradients, f)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-02-28T02:34:41.591903Z",
     "start_time": "2025-02-28T02:34:41.452302Z"
    }
   },
   "id": "e7b83531bbab71a1",
   "execution_count": 8
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "[10.0,\n 0.5752220153808594,\n -1.206587791442871,\n -2.2795982360839844,\n -1.34341561794281,\n -2.2067694664001465,\n -1.4257887601852417,\n -2.1546342372894287,\n -1.4838756322860718,\n -2.114353656768799,\n -1.528165578842163]"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gradients"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-02-28T02:34:41.597648Z",
     "start_time": "2025-02-28T02:34:41.593532Z"
    }
   },
   "id": "bbff0df6163b3a06",
   "execution_count": 9
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 12.3.2. Multivariate Gradient Descent"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "3c89ddd9ad57fa26"
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "def train_2d(trainer, steps=20, f_grad=None):  #@save\n",
    "    \"\"\"Optimize a 2D objective function with a customized trainer.\"\"\"\n",
    "    # `s1` and `s2` are internal state variables that will be used in Momentum, adagrad, RMSProp\n",
    "    x1, x2, s1, s2 = -5, -2, 0, 0\n",
    "    results = [(x1, x2)]\n",
    "    for i in range(steps):\n",
    "        if f_grad:\n",
    "            x1, x2, s1, s2 = trainer(x1, x2, s1, s2, f_grad)\n",
    "        else:\n",
    "            x1, x2, s1, s2 = trainer(x1, x2, s1, s2)\n",
    "        results.append((x1, x2))\n",
    "    print(f'epoch {i + 1}, x1: {float(x1):f}, x2: {float(x2):f}')\n",
    "    return results\n",
    "\n",
    "def show_trace_2d(f, results):  #@save\n",
    "    \"\"\"Show the trace of 2D variables during optimization.\"\"\"\n",
    "    d2l.set_figsize()\n",
    "    d2l.plt.plot(*zip(*results), '-o', color='#ff7f0e')\n",
    "    x1, x2 = torch.meshgrid(torch.arange(-5.5, 1.0, 0.1),\n",
    "                          torch.arange(-3.0, 1.0, 0.1), indexing='ij')\n",
    "    contour = d2l.plt.contour(x1, x2, f(x1, x2), colors='#1f77b4')\n",
    "    # 标注等高线的值\n",
    "    d2l.plt.clabel(contour, inline=True, fontsize=8)\n",
    "    d2l.plt.xlabel('x1')\n",
    "    d2l.plt.ylabel('x2')"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-02-28T02:34:41.607657Z",
     "start_time": "2025-02-28T02:34:41.601562Z"
    }
   },
   "id": "7e1c1b534b289ef3",
   "execution_count": 10
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "epoch 20, x1: -0.057646, x2: -0.000073\n"
     ]
    },
    {
     "data": {
      "text/plain": "<Figure size 350x250 with 1 Axes>",
      "image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"245.120313pt\" height=\"183.35625pt\" viewBox=\"0 0 245.120313 183.35625\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n   <cc:Work>\n    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n    <dc:date>2025-02-28T10:34:41.717264</dc:date>\n    <dc:format>image/svg+xml</dc:format>\n    <dc:creator>\n     <cc:Agent>\n      <dc:title>Matplotlib v3.10.0, https://matplotlib.org/</dc:title>\n     </cc:Agent>\n    </dc:creator>\n   </cc:Work>\n  </rdf:RDF>\n </metadata>\n <defs>\n  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n  <g id=\"patch_1\">\n   <path d=\"M 0 183.35625 \nL 245.120313 183.35625 \nL 245.120313 0 \nL 0 0 \nz\n\" style=\"fill: #ffffff\"/>\n  </g>\n  <g id=\"axes_1\">\n   <g id=\"patch_2\">\n    <path d=\"M 42.620312 145.8 \nL 237.920313 145.8 \nL 237.920313 7.2 \nL 42.620312 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g id=\"matplotlib.axis_1\">\n    <g id=\"xtick_1\">\n     <g id=\"line2d_1\">\n      <defs>\n       <path id=\"me95cf479e7\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#me95cf479e7\" x=\"88.39375\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_1\">\n      <!-- −4 -->\n      <g transform=\"translate(81.022656 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-2212\" d=\"M 678 2272 \nL 4684 2272 \nL 4684 1741 \nL 678 1741 \nL 678 2272 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \nL 825 1625 \nL 2419 1625 \nL 2419 4116 \nz\nM 2253 4666 \nL 3047 4666 \nL 3047 1625 \nL 3713 1625 \nL 3713 1100 \nL 3047 1100 \nL 3047 0 \nL 2419 0 \nL 2419 1100 \nL 313 1100 \nL 313 1709 \nL 2253 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-34\" transform=\"translate(83.789062 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_2\">\n     <g id=\"line2d_2\">\n      <g>\n       <use xlink:href=\"#me95cf479e7\" x=\"149.425\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_2\">\n      <!-- −2 -->\n      <g transform=\"translate(142.053907 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-32\" transform=\"translate(83.789062 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_3\">\n     <g id=\"line2d_3\">\n      <g>\n       <use xlink:href=\"#me95cf479e7\" x=\"210.456251\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_3\">\n      <!-- 0 -->\n      <g transform=\"translate(207.275001 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_4\">\n     <!-- x1 -->\n     <g transform=\"translate(134.129687 174.076563) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-78\" d=\"M 3513 3500 \nL 2247 1797 \nL 3578 0 \nL 2900 0 \nL 1881 1375 \nL 863 0 \nL 184 0 \nL 1544 1831 \nL 300 3500 \nL 978 3500 \nL 1906 2253 \nL 2834 3500 \nL 3513 3500 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-78\"/>\n      <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(59.179688 0)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_2\">\n    <g id=\"ytick_1\">\n     <g id=\"line2d_4\">\n      <defs>\n       <path id=\"m1f6a783565\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m1f6a783565\" x=\"42.620312\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_5\">\n      <!-- −3 -->\n      <g transform=\"translate(20.878125 149.599219) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \nQ 3050 2419 3304 2112 \nQ 3559 1806 3559 1356 \nQ 3559 666 3084 287 \nQ 2609 -91 1734 -91 \nQ 1441 -91 1130 -33 \nQ 819 25 488 141 \nL 488 750 \nQ 750 597 1062 519 \nQ 1375 441 1716 441 \nQ 2309 441 2620 675 \nQ 2931 909 2931 1356 \nQ 2931 1769 2642 2001 \nQ 2353 2234 1838 2234 \nL 1294 2234 \nL 1294 2753 \nL 1863 2753 \nQ 2328 2753 2575 2939 \nQ 2822 3125 2822 3475 \nQ 2822 3834 2567 4026 \nQ 2313 4219 1838 4219 \nQ 1578 4219 1281 4162 \nQ 984 4106 628 3988 \nL 628 4550 \nQ 988 4650 1302 4700 \nQ 1616 4750 1894 4750 \nQ 2613 4750 3031 4423 \nQ 3450 4097 3450 3541 \nQ 3450 3153 3228 2886 \nQ 3006 2619 2597 2516 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-33\" transform=\"translate(83.789062 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_2\">\n     <g id=\"line2d_5\">\n      <g>\n       <use xlink:href=\"#m1f6a783565\" x=\"42.620312\" y=\"110.261538\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_6\">\n      <!-- −2 -->\n      <g transform=\"translate(20.878125 114.060757) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-32\" transform=\"translate(83.789062 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_3\">\n     <g id=\"line2d_6\">\n      <g>\n       <use xlink:href=\"#m1f6a783565\" x=\"42.620312\" y=\"74.723076\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_7\">\n      <!-- −1 -->\n      <g transform=\"translate(20.878125 78.522295) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(83.789062 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_4\">\n     <g id=\"line2d_7\">\n      <g>\n       <use xlink:href=\"#m1f6a783565\" x=\"42.620312\" y=\"39.184615\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_8\">\n      <!-- 0 -->\n      <g transform=\"translate(29.257812 42.983833) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_9\">\n     <!-- x2 -->\n     <g transform=\"translate(14.798437 82.640625) rotate(-90) scale(0.1 -0.1)\">\n      <use xlink:href=\"#DejaVuSans-78\"/>\n      <use xlink:href=\"#DejaVuSans-32\" transform=\"translate(59.179688 0)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"line2d_8\">\n    <path d=\"M 57.878125 110.261538 \nL 88.39375 81.830769 \nL 112.80625 64.772307 \nL 132.33625 54.53723 \nL 147.96025 48.396184 \nL 160.45945 44.711556 \nL 170.45881 42.50078 \nL 178.458299 41.174314 \nL 184.857889 40.378434 \nL 189.977561 39.900906 \nL 194.073299 39.61439 \nL 197.349889 39.44248 \nL 199.971162 39.339334 \nL 202.068179 39.277446 \nL 203.745794 39.240314 \nL 205.087885 39.218034 \nL 206.161558 39.204666 \nL 207.020497 39.196646 \nL 207.707647 39.191833 \nL 208.257368 39.188946 \nL 208.697145 39.187213 \n\" clip-path=\"url(#pe888728594)\" style=\"fill: none; stroke: #ff7f0e; stroke-width: 1.5; stroke-linecap: square\"/>\n    <defs>\n     <path id=\"m439de1c2a6\" d=\"M 0 3 \nC 0.795609 3 1.55874 2.683901 2.12132 2.12132 \nC 2.683901 1.55874 3 0.795609 3 0 \nC 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \nC 1.55874 -2.683901 0.795609 -3 0 -3 \nC -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \nC -2.683901 -1.55874 -3 -0.795609 -3 0 \nC -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \nC -1.55874 2.683901 -0.795609 3 0 3 \nz\n\" style=\"stroke: #ff7f0e\"/>\n    </defs>\n    <g clip-path=\"url(#pe888728594)\">\n     <use xlink:href=\"#m439de1c2a6\" x=\"57.878125\" y=\"110.261538\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m439de1c2a6\" x=\"88.39375\" y=\"81.830769\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m439de1c2a6\" x=\"112.80625\" y=\"64.772307\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m439de1c2a6\" x=\"132.33625\" y=\"54.53723\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m439de1c2a6\" x=\"147.96025\" y=\"48.396184\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m439de1c2a6\" x=\"160.45945\" y=\"44.711556\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m439de1c2a6\" x=\"170.45881\" y=\"42.50078\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m439de1c2a6\" x=\"178.458299\" y=\"41.174314\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m439de1c2a6\" x=\"184.857889\" y=\"40.378434\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m439de1c2a6\" x=\"189.977561\" y=\"39.900906\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m439de1c2a6\" x=\"194.073299\" y=\"39.61439\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m439de1c2a6\" x=\"197.349889\" y=\"39.44248\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m439de1c2a6\" x=\"199.971162\" y=\"39.339334\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m439de1c2a6\" x=\"202.068179\" y=\"39.277446\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m439de1c2a6\" x=\"203.745794\" y=\"39.240314\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m439de1c2a6\" x=\"205.087885\" y=\"39.218034\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m439de1c2a6\" x=\"206.161558\" y=\"39.204666\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m439de1c2a6\" x=\"207.020497\" y=\"39.196646\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m439de1c2a6\" x=\"207.707647\" y=\"39.191833\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m439de1c2a6\" x=\"208.257368\" y=\"39.188946\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m439de1c2a6\" x=\"208.697145\" y=\"39.187213\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n    </g>\n   </g>\n   <g id=\"QuadContourSet_1\">\n    <path clip-path=\"url(#pe888728594)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5\"/>\n    <path d=\"M 133.389338 7.2 \nL 131.354961 10.753845 \nL 131.115628 11.22768 \nL 129.618631 14.307692 \nL 128.121641 17.861537 \nL 128.064069 18.023063 \nL 126.898922 21.415384 \nL 125.900228 24.96923 \nL 125.123465 28.523076 \nL 125.012502 29.233828 \nL 124.58421 32.076922 \nL 124.262994 35.630769 \nL 124.155921 39.184616 \nL 124.262994 42.738462 \nL 124.58421 46.292308 \nL 125.012502 49.135401 \nL 125.123465 49.846154 \nL 125.900228 53.400001 \nL 126.898922 56.953846 \nL 128.064069 60.346166 \nL 128.121641 60.507693 \nL 129.618631 64.061538 \nL 131.115628 67.141548 \nL 131.354961 67.615382 \nL 133.389338 71.169229 \nL 134.167188 72.38502 \nL 135.724107 74.723076 \nL 137.218755 76.753852 \nL 138.387435 78.276924 \nL 140.270314 80.517389 \nL 141.423126 81.830766 \nL 143.321874 83.820924 \nL 144.883135 85.384613 \nL 146.373441 86.766672 \nL 148.829573 88.93846 \nL 149.425 89.428646 \nL 152.476564 91.818304 \nL 153.383783 92.492307 \nL 155.528127 93.98263 \nL 158.57969 95.988833 \nL 158.672164 96.046154 \nL 161.631253 97.76923 \nL 164.682813 99.438459 \nL 164.998499 99.600001 \nL 167.734376 100.92 \nL 170.785939 102.290771 \nL 172.861005 103.153848 \nL 173.837499 103.538045 \nL 176.889062 104.64262 \nL 179.940626 105.651142 \nL 182.992189 106.563617 \nL 183.530712 106.707695 \nL 186.04375 107.345562 \nL 189.095313 108.028995 \nL 192.146877 108.621302 \nL 195.198438 109.122485 \nL 198.250001 109.532545 \nL 201.251513 109.846247 \nM 213.568947 110.213237 \nL 216.559376 110.07929 \nL 219.610939 109.851478 \nL 222.662501 109.532545 \nL 225.714063 109.122485 \nL 228.765626 108.621302 \nL 231.817188 108.028995 \nL 234.868751 107.345562 \nL 237.38179 106.707695 \nL 237.920313 106.563617 \n\" clip-path=\"url(#pe888728594)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5\"/>\n    <path d=\"M 94.741 7.2 \nL 94.496869 7.827163 \nL 93.387217 10.753845 \nL 92.198295 14.307692 \nL 91.44531 16.904747 \nL 91.174923 17.861537 \nL 90.325119 21.415384 \nL 89.629825 24.96923 \nL 89.089044 28.523076 \nL 88.702769 32.076922 \nL 88.471007 35.630769 \nL 88.393757 39.184277 \nL 88.39375 39.184616 \nL 88.393757 39.184954 \nL 88.471007 42.738462 \nL 88.702769 46.292308 \nL 89.089044 49.846154 \nL 89.629825 53.400001 \nL 90.325119 56.953846 \nL 91.174923 60.507693 \nL 91.44531 61.464482 \nL 92.198295 64.061538 \nL 93.387217 67.615382 \nL 94.496869 70.542066 \nL 94.741 71.169229 \nL 96.287127 74.723076 \nL 97.548436 77.346149 \nL 98.008263 78.276924 \nL 99.931161 81.830766 \nL 100.599996 82.967996 \nL 102.061308 85.384613 \nL 103.651563 87.819658 \nL 104.403397 88.93846 \nL 106.703122 92.12466 \nL 106.976403 92.492307 \nL 109.754682 95.988822 \nL 109.801639 96.046154 \nL 112.806249 99.492307 \nL 112.903126 99.600001 \nL 115.857816 102.696925 \nL 116.308047 103.153848 \nL 118.909375 105.651142 \nL 120.04725 106.707695 \nL 121.960942 108.393495 \nL 124.155924 110.261538 \nL 125.012502 110.954971 \nL 128.064069 113.338652 \nL 128.697415 113.81539 \nL 131.115628 115.550988 \nL 133.748347 117.369232 \nL 134.167188 117.645641 \nL 137.218755 119.580512 \nL 139.426266 120.923075 \nL 140.270314 121.414565 \nL 143.321874 123.115875 \nL 145.876677 124.476926 \nL 146.373441 124.730771 \nL 149.425 126.217583 \nL 152.476564 127.631866 \nL 153.383788 128.030769 \nL 154.369787 128.447308 \nM 170.654114 134.194132 \nL 170.785939 134.233237 \nL 173.837499 135.071408 \nL 174.102859 135.138463 \nL 176.889062 135.816922 \nL 179.940626 136.495383 \nL 182.992189 137.109229 \nL 186.04375 137.65846 \nL 189.095313 138.143075 \nL 192.146877 138.563078 \nL 193.256511 138.692306 \nL 195.198438 138.910526 \nL 198.250001 139.191094 \nL 201.301564 139.409311 \nL 204.353126 139.565181 \nL 207.404689 139.658704 \nL 210.456251 139.689878 \nL 213.507813 139.658704 \nL 216.559376 139.565181 \nL 219.610939 139.409311 \nL 222.662501 139.191094 \nL 225.714063 138.910526 \nL 227.655991 138.692306 \nL 228.765626 138.563078 \nL 231.817188 138.143075 \nL 234.868751 137.65846 \nL 237.920313 137.109229 \n\" clip-path=\"url(#pe888728594)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5\"/>\n    <path d=\"M 66.101283 7.2 \nL 65.009145 10.753845 \nL 64.045489 14.307692 \nL 63.981244 14.581071 \nL 63.226219 17.861537 \nL 62.534115 21.415384 \nL 61.967845 24.96923 \nL 61.527415 28.523076 \nL 61.21282 32.076922 \nL 61.024065 35.630769 \nL 60.961145 39.184616 \nL 61.024065 42.738462 \nL 61.21282 46.292308 \nL 61.527415 49.846154 \nL 61.967845 53.400001 \nL 62.534115 56.953846 \nL 63.226219 60.507693 \nL 63.981244 63.788159 \nL 64.045489 64.061538 \nL 65.009145 67.615382 \nL 66.101283 71.169229 \nL 67.032818 73.88139 \nL 67.328125 74.723076 \nL 68.706252 78.276924 \nL 70.084378 81.521744 \nL 70.218509 81.830766 \nL 71.895191 85.384613 \nL 73.135938 87.819658 \nL 73.718821 88.93846 \nL 75.70748 92.492307 \nL 76.187512 93.294806 \nL 77.871125 96.046154 \nL 79.239071 98.146162 \nL 80.208385 99.600001 \nL 82.290631 102.544624 \nL 82.731817 103.153848 \nL 85.342191 106.563617 \nL 85.455214 106.707695 \nL 88.39375 110.261538 \nL 88.393757 110.261547 \nL 91.44531 113.68536 \nL 91.564212 113.81539 \nL 94.496869 116.873336 \nL 94.98513 117.369232 \nL 97.548436 119.85692 \nL 98.677098 120.923075 \nL 100.049139 122.163981 \nM 113.711657 133.015953 \nL 115.857816 134.501452 \nL 116.808306 135.138463 \nL 118.909375 136.495381 \nL 121.960942 138.401542 \nL 122.442758 138.692306 \nL 125.012502 140.188665 \nL 128.064069 141.903241 \nL 128.697416 142.246157 \nL 131.115628 143.511083 \nL 134.167188 145.047066 \nL 135.724104 145.8 \n\" clip-path=\"url(#pe888728594)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5\"/>\n    <path d=\"M 42.620312 72.385026 \nL 43.320213 74.723076 \nL 44.496043 78.276924 \nL 45.671872 81.521729 \nL 45.785952 81.830766 \nL 47.211915 85.384613 \nL 48.723432 88.872634 \nL 48.7525 88.93846 \nL 50.438126 92.492307 \nL 51.775006 95.129054 \nL 52.249024 96.046154 \nL 54.204398 99.600001 \nL 54.826565 100.666162 \nL 56.307021 103.153848 \nL 57.878125 105.651143 \nL 58.556253 106.707695 \nL 60.929685 110.215966 \nL 60.961151 110.261538 \nL 61.76755 111.372465 \nM 72.708992 124.849286 \nL 73.135938 125.31099 \nL 75.70748 128.030769 \nL 76.187512 128.518562 \nL 79.239071 131.549789 \nL 79.274952 131.584612 \nL 82.290631 134.400881 \nL 83.09947 135.138463 \nL 85.342191 137.109235 \nL 87.188189 138.692306 \nL 88.393757 139.689886 \nL 91.44531 142.152627 \nL 91.564212 142.246157 \nL 94.496869 144.474831 \nL 96.287127 145.8 \n\" clip-path=\"url(#pe888728594)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5\"/>\n    <path d=\"M 42.620312 117.645641 \nL 44.943982 120.923075 \nL 45.671872 121.90605 \nL 47.611182 124.476926 \nL 47.92297 124.873379 \nM 59.301191 137.986957 \nL 59.974143 138.692306 \nL 60.929685 139.658706 \nL 63.540815 142.246157 \nL 63.981244 142.667798 \nL 67.032818 145.528954 \nL 67.32812 145.8 \n\" clip-path=\"url(#pe888728594)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5\"/>\n    <path d=\"M 42.620312 145.047067 \nL 43.320214 145.8 \n\" clip-path=\"url(#pe888728594)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5\"/>\n    <path clip-path=\"url(#pe888728594)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5\"/>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 42.620312 145.8 \nL 42.620312 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_4\">\n    <path d=\"M 237.920313 145.8 \nL 237.920313 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_5\">\n    <path d=\"M 42.620312 145.8 \nL 237.920313 145.8 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_6\">\n    <path d=\"M 42.620312 7.2 \nL 237.920313 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"text_10\">\n    <g clip-path=\"url(#pe888728594)\">\n     <!-- 8 -->\n     <g style=\"fill: #1f77b4\" transform=\"translate(204.794947 112.346545) rotate(-358.289952) scale(0.08 -0.08)\">\n      <defs>\n       <path id=\"DejaVuSans-38\" d=\"M 2034 2216 \nQ 1584 2216 1326 1975 \nQ 1069 1734 1069 1313 \nQ 1069 891 1326 650 \nQ 1584 409 2034 409 \nQ 2484 409 2743 651 \nQ 3003 894 3003 1313 \nQ 3003 1734 2745 1975 \nQ 2488 2216 2034 2216 \nz\nM 1403 2484 \nQ 997 2584 770 2862 \nQ 544 3141 544 3541 \nQ 544 4100 942 4425 \nQ 1341 4750 2034 4750 \nQ 2731 4750 3128 4425 \nQ 3525 4100 3525 3541 \nQ 3525 3141 3298 2862 \nQ 3072 2584 2669 2484 \nQ 3125 2378 3379 2068 \nQ 3634 1759 3634 1313 \nQ 3634 634 3220 271 \nQ 2806 -91 2034 -91 \nQ 1263 -91 848 271 \nQ 434 634 434 1313 \nQ 434 1759 690 2068 \nQ 947 2378 1403 2484 \nz\nM 1172 3481 \nQ 1172 3119 1398 2916 \nQ 1625 2713 2034 2713 \nQ 2441 2713 2670 2916 \nQ 2900 3119 2900 3481 \nQ 2900 3844 2670 4047 \nQ 2441 4250 2034 4250 \nQ 1625 4250 1398 4047 \nQ 1172 3844 1172 3481 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-38\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"text_11\">\n    <g clip-path=\"url(#pe888728594)\">\n     <!-- 16 -->\n     <g style=\"fill: #1f77b4\" transform=\"translate(156.884218 131.972275) rotate(-340.560656) scale(0.08 -0.08)\">\n      <defs>\n       <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \nQ 1688 2584 1439 2293 \nQ 1191 2003 1191 1497 \nQ 1191 994 1439 701 \nQ 1688 409 2113 409 \nQ 2538 409 2786 701 \nQ 3034 994 3034 1497 \nQ 3034 2003 2786 2293 \nQ 2538 2584 2113 2584 \nz\nM 3366 4563 \nL 3366 3988 \nQ 3128 4100 2886 4159 \nQ 2644 4219 2406 4219 \nQ 1781 4219 1451 3797 \nQ 1122 3375 1075 2522 \nQ 1259 2794 1537 2939 \nQ 1816 3084 2150 3084 \nQ 2853 3084 3261 2657 \nQ 3669 2231 3669 1497 \nQ 3669 778 3244 343 \nQ 2819 -91 2113 -91 \nQ 1303 -91 875 529 \nQ 447 1150 447 2328 \nQ 447 3434 972 4092 \nQ 1497 4750 2381 4750 \nQ 2619 4750 2861 4703 \nQ 3103 4656 3366 4563 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-31\"/>\n      <use xlink:href=\"#DejaVuSans-36\" transform=\"translate(63.623047 0)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"text_12\">\n    <g clip-path=\"url(#pe888728594)\">\n     <!-- 24 -->\n     <g style=\"fill: #1f77b4\" transform=\"translate(101.343175 126.380658) rotate(-321.590541) scale(0.08 -0.08)\">\n      <use xlink:href=\"#DejaVuSans-32\"/>\n      <use xlink:href=\"#DejaVuSans-34\" transform=\"translate(63.623047 0)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"text_13\">\n    <g clip-path=\"url(#pe888728594)\">\n     <!-- 32 -->\n     <g style=\"fill: #1f77b4\" transform=\"translate(62.107348 115.723837) rotate(-309.149494) scale(0.08 -0.08)\">\n      <use xlink:href=\"#DejaVuSans-33\"/>\n      <use xlink:href=\"#DejaVuSans-32\" transform=\"translate(63.623047 0)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"text_14\">\n    <g clip-path=\"url(#pe888728594)\">\n     <!-- 40 -->\n     <g style=\"fill: #1f77b4\" transform=\"translate(48.431468 129.18569) rotate(-310.934735) scale(0.08 -0.08)\">\n      <use xlink:href=\"#DejaVuSans-34\"/>\n      <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n     </g>\n    </g>\n   </g>\n  </g>\n </g>\n <defs>\n  <clipPath id=\"pe888728594\">\n   <rect x=\"42.620312\" y=\"7.2\" width=\"195.3\" height=\"138.6\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def f_2d(x1, x2):  # Objective function\n",
    "    return x1 ** 2 + 2 * x2 ** 2\n",
    "\n",
    "def f_2d_grad(x1, x2):  # Gradient of the objective function\n",
    "    return (2 * x1, 4 * x2)\n",
    "\n",
    "def gd_2d(x1, x2, s1, s2, f_grad):\n",
    "    g1, g2 = f_grad(x1, x2)\n",
    "    return (x1 - eta * g1, x2 - eta * g2, 0, 0)\n",
    "\n",
    "eta = 0.1\n",
    "show_trace_2d(f_2d, train_2d(gd_2d, f_grad=f_2d_grad))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-02-28T02:34:41.745704Z",
     "start_time": "2025-02-28T02:34:41.609452Z"
    }
   },
   "id": "4e9b74aa57f46413",
   "execution_count": 11
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 12.3.3. Adaptive Methods\n",
    "## 12.3.3.1. Newton’s Method"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "402adc896a43d9fe"
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "epoch 10, x: tensor(0.)\n"
     ]
    },
    {
     "data": {
      "text/plain": "<Figure size 350x250 with 1 Axes>",
      "image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"243.103125pt\" height=\"183.35625pt\" viewBox=\"0 0 243.103125 183.35625\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n   <cc:Work>\n    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n    <dc:date>2025-02-28T10:34:41.872505</dc:date>\n    <dc:format>image/svg+xml</dc:format>\n    <dc:creator>\n     <cc:Agent>\n      <dc:title>Matplotlib v3.10.0, https://matplotlib.org/</dc:title>\n     </cc:Agent>\n    </dc:creator>\n   </cc:Work>\n  </rdf:RDF>\n </metadata>\n <defs>\n  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n  <g id=\"patch_1\">\n   <path d=\"M 0 183.35625 \nL 243.103125 183.35625 \nL 243.103125 0 \nL 0 0 \nz\n\" style=\"fill: #ffffff\"/>\n  </g>\n  <g id=\"axes_1\">\n   <g id=\"patch_2\">\n    <path d=\"M 40.603125 145.8 \nL 235.903125 145.8 \nL 235.903125 7.2 \nL 40.603125 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g id=\"matplotlib.axis_1\">\n    <g id=\"xtick_1\">\n     <g id=\"line2d_1\">\n      <path d=\"M 49.480398 145.8 \nL 49.480398 7.2 \n\" clip-path=\"url(#p67db9ffc08)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_2\">\n      <defs>\n       <path id=\"mbd17676abb\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#mbd17676abb\" x=\"49.480398\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_1\">\n      <!-- −10 -->\n      <g transform=\"translate(38.928054 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-2212\" d=\"M 678 2272 \nL 4684 2272 \nL 4684 1741 \nL 678 1741 \nL 678 2272 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(83.789062 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(147.412109 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_2\">\n     <g id=\"line2d_3\">\n      <path d=\"M 93.866761 145.8 \nL 93.866761 7.2 \n\" clip-path=\"url(#p67db9ffc08)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_4\">\n      <g>\n       <use xlink:href=\"#mbd17676abb\" x=\"93.866761\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_2\">\n      <!-- −5 -->\n      <g transform=\"translate(86.495668 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \nL 3169 4666 \nL 3169 4134 \nL 1269 4134 \nL 1269 2991 \nQ 1406 3038 1543 3061 \nQ 1681 3084 1819 3084 \nQ 2600 3084 3056 2656 \nQ 3513 2228 3513 1497 \nQ 3513 744 3044 326 \nQ 2575 -91 1722 -91 \nQ 1428 -91 1123 -41 \nQ 819 9 494 109 \nL 494 744 \nQ 775 591 1075 516 \nQ 1375 441 1709 441 \nQ 2250 441 2565 725 \nQ 2881 1009 2881 1497 \nQ 2881 1984 2565 2268 \nQ 2250 2553 1709 2553 \nQ 1456 2553 1204 2497 \nQ 953 2441 691 2322 \nL 691 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(83.789062 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_3\">\n     <g id=\"line2d_5\">\n      <path d=\"M 138.253125 145.8 \nL 138.253125 7.2 \n\" clip-path=\"url(#p67db9ffc08)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_6\">\n      <g>\n       <use xlink:href=\"#mbd17676abb\" x=\"138.253125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_3\">\n      <!-- 0 -->\n      <g transform=\"translate(135.071875 160.398438) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_4\">\n     <g id=\"line2d_7\">\n      <path d=\"M 182.639489 145.8 \nL 182.639489 7.2 \n\" clip-path=\"url(#p67db9ffc08)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_8\">\n      <g>\n       <use xlink:href=\"#mbd17676abb\" x=\"182.639489\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_4\">\n      <!-- 5 -->\n      <g transform=\"translate(179.458239 160.398438) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-35\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_5\">\n     <g id=\"line2d_9\">\n      <path d=\"M 227.025852 145.8 \nL 227.025852 7.2 \n\" clip-path=\"url(#p67db9ffc08)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_10\">\n      <g>\n       <use xlink:href=\"#mbd17676abb\" x=\"227.025852\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_5\">\n      <!-- 10 -->\n      <g transform=\"translate(220.663352 160.398438) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_6\">\n     <!-- x -->\n     <g transform=\"translate(135.29375 174.076563) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-78\" d=\"M 3513 3500 \nL 2247 1797 \nL 3578 0 \nL 2900 0 \nL 1881 1375 \nL 863 0 \nL 184 0 \nL 1544 1831 \nL 300 3500 \nL 978 3500 \nL 1906 2253 \nL 2834 3500 \nL 3513 3500 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-78\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_2\">\n    <g id=\"ytick_1\">\n     <g id=\"line2d_11\">\n      <path d=\"M 40.603125 141.221078 \nL 235.903125 141.221078 \n\" clip-path=\"url(#p67db9ffc08)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_12\">\n      <defs>\n       <path id=\"me58e890d0c\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#me58e890d0c\" x=\"40.603125\" y=\"141.221078\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_7\">\n      <!-- 0 -->\n      <g transform=\"translate(27.240625 145.020296) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_2\">\n     <g id=\"line2d_13\">\n      <path d=\"M 40.603125 106.799525 \nL 235.903125 106.799525 \n\" clip-path=\"url(#p67db9ffc08)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_14\">\n      <g>\n       <use xlink:href=\"#me58e890d0c\" x=\"40.603125\" y=\"106.799525\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_8\">\n      <!-- 20 -->\n      <g transform=\"translate(20.878125 110.598744) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-32\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_3\">\n     <g id=\"line2d_15\">\n      <path d=\"M 40.603125 72.377972 \nL 235.903125 72.377972 \n\" clip-path=\"url(#p67db9ffc08)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_16\">\n      <g>\n       <use xlink:href=\"#me58e890d0c\" x=\"40.603125\" y=\"72.377972\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_9\">\n      <!-- 40 -->\n      <g transform=\"translate(20.878125 76.177191) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \nL 825 1625 \nL 2419 1625 \nL 2419 4116 \nz\nM 2253 4666 \nL 3047 4666 \nL 3047 1625 \nL 3713 1625 \nL 3713 1100 \nL 3047 1100 \nL 3047 0 \nL 2419 0 \nL 2419 1100 \nL 313 1100 \nL 313 1709 \nL 2253 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-34\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_4\">\n     <g id=\"line2d_17\">\n      <path d=\"M 40.603125 37.95642 \nL 235.903125 37.95642 \n\" clip-path=\"url(#p67db9ffc08)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_18\">\n      <g>\n       <use xlink:href=\"#me58e890d0c\" x=\"40.603125\" y=\"37.95642\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_10\">\n      <!-- 60 -->\n      <g transform=\"translate(20.878125 41.755638) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \nQ 1688 2584 1439 2293 \nQ 1191 2003 1191 1497 \nQ 1191 994 1439 701 \nQ 1688 409 2113 409 \nQ 2538 409 2786 701 \nQ 3034 994 3034 1497 \nQ 3034 2003 2786 2293 \nQ 2538 2584 2113 2584 \nz\nM 3366 4563 \nL 3366 3988 \nQ 3128 4100 2886 4159 \nQ 2644 4219 2406 4219 \nQ 1781 4219 1451 3797 \nQ 1122 3375 1075 2522 \nQ 1259 2794 1537 2939 \nQ 1816 3084 2150 3084 \nQ 2853 3084 3261 2657 \nQ 3669 2231 3669 1497 \nQ 3669 778 3244 343 \nQ 2819 -91 2113 -91 \nQ 1303 -91 875 529 \nQ 447 1150 447 2328 \nQ 447 3434 972 4092 \nQ 1497 4750 2381 4750 \nQ 2619 4750 2861 4703 \nQ 3103 4656 3366 4563 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-36\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_11\">\n     <!-- f(x) -->\n     <g transform=\"translate(14.798437 85.121094) rotate(-90) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-66\" d=\"M 2375 4863 \nL 2375 4384 \nL 1825 4384 \nQ 1516 4384 1395 4259 \nQ 1275 4134 1275 3809 \nL 1275 3500 \nL 2222 3500 \nL 2222 3053 \nL 1275 3053 \nL 1275 0 \nL 697 0 \nL 697 3053 \nL 147 3053 \nL 147 3500 \nL 697 3500 \nL 697 3744 \nQ 697 4328 969 4595 \nQ 1241 4863 1831 4863 \nL 2375 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-28\" d=\"M 1984 4856 \nQ 1566 4138 1362 3434 \nQ 1159 2731 1159 2009 \nQ 1159 1288 1364 580 \nQ 1569 -128 1984 -844 \nL 1484 -844 \nQ 1016 -109 783 600 \nQ 550 1309 550 2009 \nQ 550 2706 781 3412 \nQ 1013 4119 1484 4856 \nL 1984 4856 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-29\" d=\"M 513 4856 \nL 1013 4856 \nQ 1481 4119 1714 3412 \nQ 1947 2706 1947 2009 \nQ 1947 1309 1714 600 \nQ 1481 -109 1013 -844 \nL 513 -844 \nQ 928 -128 1133 580 \nQ 1338 1288 1338 2009 \nQ 1338 2731 1133 3434 \nQ 928 4138 513 4856 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-66\"/>\n      <use xlink:href=\"#DejaVuSans-28\" transform=\"translate(35.205078 0)\"/>\n      <use xlink:href=\"#DejaVuSans-78\" transform=\"translate(74.21875 0)\"/>\n      <use xlink:href=\"#DejaVuSans-29\" transform=\"translate(133.398438 0)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"line2d_19\">\n    <path d=\"M 49.480398 13.5 \nL 51.522166 27.37347 \nL 53.563944 39.739698 \nL 55.605721 50.762351 \nL 57.647489 60.587326 \nL 59.689258 69.344749 \nL 61.731035 77.150591 \nL 63.772812 84.108164 \nL 65.814581 90.30956 \nL 67.856354 95.836922 \nL 69.986897 100.96501 \nL 72.117445 105.512725 \nL 74.247988 109.545614 \nL 76.378536 113.121838 \nL 78.597854 116.416973 \nL 80.817172 119.324039 \nL 83.125265 121.98456 \nL 85.522124 124.403374 \nL 88.007763 126.588069 \nL 90.582171 128.54842 \nL 93.245355 130.295943 \nL 96.08608 131.889371 \nL 99.104354 133.3209 \nL 102.300173 134.587955 \nL 105.762306 135.718534 \nL 109.490761 136.702398 \nL 113.66308 137.567962 \nL 118.279261 138.291055 \nL 123.339307 138.85625 \nL 129.020762 139.26202 \nL 135.14608 139.473579 \nL 141.537716 139.470464 \nL 147.751806 139.247761 \nL 153.522033 138.823339 \nL 158.759624 138.218588 \nL 163.464579 137.452921 \nL 167.636897 136.553367 \nL 171.454125 135.505017 \nL 174.916262 134.32634 \nL 178.112082 133.006078 \nL 181.041581 131.562581 \nL 183.793535 129.967314 \nL 186.456719 128.166 \nL 188.942353 126.220171 \nL 191.339216 124.065401 \nL 193.647305 121.694992 \nL 195.866627 119.104643 \nL 198.085941 116.168286 \nL 200.216489 112.98125 \nL 202.347032 109.38708 \nL 204.388809 105.512718 \nL 206.430578 101.165609 \nL 208.472355 96.288161 \nL 210.514128 90.815833 \nL 212.555897 84.676176 \nL 214.508899 78.104122 \nL 216.461901 70.767581 \nL 218.414895 62.577729 \nL 220.367898 53.435299 \nL 222.320892 43.229629 \nL 224.273902 31.836971 \nL 226.226896 19.119528 \nL 226.937078 14.136961 \nL 226.937078 14.136961 \n\" clip-path=\"url(#p67db9ffc08)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n   </g>\n   <g id=\"line2d_20\">\n    <path d=\"M 227.025852 13.5 \nL 209.272915 94.217234 \nL 191.530277 123.880719 \nL 173.863402 134.710367 \nL 156.740422 138.479555 \nL 142.920469 139.440188 \nL 138.357749 139.49997 \nL 138.253126 139.5 \nL 138.253125 139.5 \nL 138.253125 139.5 \nL 138.253125 139.5 \n\" clip-path=\"url(#p67db9ffc08)\" style=\"fill: none; stroke: #ff7f0e; stroke-width: 1.5; stroke-linecap: square\"/>\n    <defs>\n     <path id=\"m3cc70e8c65\" d=\"M 0 3 \nC 0.795609 3 1.55874 2.683901 2.12132 2.12132 \nC 2.683901 1.55874 3 0.795609 3 0 \nC 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \nC 1.55874 -2.683901 0.795609 -3 0 -3 \nC -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \nC -2.683901 -1.55874 -3 -0.795609 -3 0 \nC -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \nC -1.55874 2.683901 -0.795609 3 0 3 \nz\n\" style=\"stroke: #ff7f0e\"/>\n    </defs>\n    <g clip-path=\"url(#p67db9ffc08)\">\n     <use xlink:href=\"#m3cc70e8c65\" x=\"227.025852\" y=\"13.5\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m3cc70e8c65\" x=\"209.272915\" y=\"94.217234\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m3cc70e8c65\" x=\"191.530277\" y=\"123.880719\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m3cc70e8c65\" x=\"173.863402\" y=\"134.710367\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m3cc70e8c65\" x=\"156.740422\" y=\"138.479555\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m3cc70e8c65\" x=\"142.920469\" y=\"139.440188\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m3cc70e8c65\" x=\"138.357749\" y=\"139.49997\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m3cc70e8c65\" x=\"138.253126\" y=\"139.5\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m3cc70e8c65\" x=\"138.253125\" y=\"139.5\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m3cc70e8c65\" x=\"138.253125\" y=\"139.5\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m3cc70e8c65\" x=\"138.253125\" y=\"139.5\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n    </g>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 40.603125 145.8 \nL 40.603125 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_4\">\n    <path d=\"M 235.903125 145.8 \nL 235.903125 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_5\">\n    <path d=\"M 40.603125 145.8 \nL 235.903125 145.8 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_6\">\n    <path d=\"M 40.603125 7.2 \nL 235.903125 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n </g>\n <defs>\n  <clipPath id=\"p67db9ffc08\">\n   <rect x=\"40.603125\" y=\"7.2\" width=\"195.3\" height=\"138.6\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "c = torch.tensor(0.5)\n",
    "\n",
    "def f(x):  # Objective function\n",
    "    return torch.cosh(c * x)\n",
    "\n",
    "def f_grad(x):  # Gradient of the objective function\n",
    "    return c * torch.sinh(c * x)\n",
    "\n",
    "def f_hess(x):  # Hessian of the objective function\n",
    "    return c**2 * torch.cosh(c * x)\n",
    "\n",
    "def newton(eta=1):\n",
    "    x = 10.0\n",
    "    results = [x]\n",
    "    for i in range(10):\n",
    "        x -= eta * f_grad(x) / f_hess(x)\n",
    "        results.append(float(x))\n",
    "    print('epoch 10, x:', x)\n",
    "    return results\n",
    "\n",
    "show_trace(newton(), f)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-02-28T02:34:41.902554Z",
     "start_time": "2025-02-28T02:34:41.747650Z"
    }
   },
   "id": "a86a9adb7602092d",
   "execution_count": 12
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "epoch 10, x: tensor(26.8341)\n",
      "[10.0, 5.0, 24.994861602783203, 27.78314208984375, 26.800092697143555, 26.834177017211914, 26.834131240844727, 26.83413314819336, 26.83413314819336, 26.83413314819336, 26.83413314819336]\n"
     ]
    },
    {
     "data": {
      "text/plain": "<Figure size 350x250 with 1 Axes>",
      "image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"251.482813pt\" height=\"183.35625pt\" viewBox=\"0 0 251.482813 183.35625\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n   <cc:Work>\n    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n    <dc:date>2025-02-28T10:34:42.084974</dc:date>\n    <dc:format>image/svg+xml</dc:format>\n    <dc:creator>\n     <cc:Agent>\n      <dc:title>Matplotlib v3.10.0, https://matplotlib.org/</dc:title>\n     </cc:Agent>\n    </dc:creator>\n   </cc:Work>\n  </rdf:RDF>\n </metadata>\n <defs>\n  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n  <g id=\"patch_1\">\n   <path d=\"M -0 183.35625 \nL 251.482813 183.35625 \nL 251.482813 0 \nL -0 0 \nz\n\" style=\"fill: #ffffff\"/>\n  </g>\n  <g id=\"axes_1\">\n   <g id=\"patch_2\">\n    <path d=\"M 48.982813 145.8 \nL 244.282813 145.8 \nL 244.282813 7.2 \nL 48.982813 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g id=\"matplotlib.axis_1\">\n    <g id=\"xtick_1\">\n     <g id=\"line2d_1\">\n      <path d=\"M 82.72879 145.8 \nL 82.72879 7.2 \n\" clip-path=\"url(#p09f25f1efe)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_2\">\n      <defs>\n       <path id=\"m29cb8b2874\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m29cb8b2874\" x=\"82.72879\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_1\">\n      <!-- −20 -->\n      <g transform=\"translate(72.176446 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-2212\" d=\"M 678 2272 \nL 4684 2272 \nL 4684 1741 \nL 678 1741 \nL 678 2272 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-32\" transform=\"translate(83.789062 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(147.412109 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_2\">\n     <g id=\"line2d_3\">\n      <path d=\"M 146.632812 145.8 \nL 146.632812 7.2 \n\" clip-path=\"url(#p09f25f1efe)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_4\">\n      <g>\n       <use xlink:href=\"#m29cb8b2874\" x=\"146.632812\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_2\">\n      <!-- 0 -->\n      <g transform=\"translate(143.451562 160.398438) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_3\">\n     <g id=\"line2d_5\">\n      <path d=\"M 210.536835 145.8 \nL 210.536835 7.2 \n\" clip-path=\"url(#p09f25f1efe)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_6\">\n      <g>\n       <use xlink:href=\"#m29cb8b2874\" x=\"210.536835\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_3\">\n      <!-- 20 -->\n      <g transform=\"translate(204.174335 160.398438) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-32\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_4\">\n     <!-- x -->\n     <g transform=\"translate(143.673438 174.076563) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-78\" d=\"M 3513 3500 \nL 2247 1797 \nL 3578 0 \nL 2900 0 \nL 1881 1375 \nL 863 0 \nL 184 0 \nL 1544 1831 \nL 300 3500 \nL 978 3500 \nL 1906 2253 \nL 2834 3500 \nL 3513 3500 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-78\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_2\">\n    <g id=\"ytick_1\">\n     <g id=\"line2d_7\">\n      <path d=\"M 48.982813 123.601723 \nL 244.282813 123.601723 \n\" clip-path=\"url(#p09f25f1efe)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_8\">\n      <defs>\n       <path id=\"m49c220cd1c\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m49c220cd1c\" x=\"48.982813\" y=\"123.601723\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_5\">\n      <!-- −20 -->\n      <g transform=\"translate(20.878125 127.400942) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-32\" transform=\"translate(83.789062 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(147.412109 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_2\">\n     <g id=\"line2d_9\">\n      <path d=\"M 48.982813 100.050863 \nL 244.282813 100.050863 \n\" clip-path=\"url(#p09f25f1efe)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_10\">\n      <g>\n       <use xlink:href=\"#m49c220cd1c\" x=\"48.982813\" y=\"100.050863\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_6\">\n      <!-- −10 -->\n      <g transform=\"translate(20.878125 103.850081) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(83.789062 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(147.412109 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_3\">\n     <g id=\"line2d_11\">\n      <path d=\"M 48.982813 76.500002 \nL 244.282813 76.500002 \n\" clip-path=\"url(#p09f25f1efe)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_12\">\n      <g>\n       <use xlink:href=\"#m49c220cd1c\" x=\"48.982813\" y=\"76.500002\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_7\">\n      <!-- 0 -->\n      <g transform=\"translate(35.620313 80.299221) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_4\">\n     <g id=\"line2d_13\">\n      <path d=\"M 48.982813 52.949142 \nL 244.282813 52.949142 \n\" clip-path=\"url(#p09f25f1efe)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_14\">\n      <g>\n       <use xlink:href=\"#m49c220cd1c\" x=\"48.982813\" y=\"52.949142\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_8\">\n      <!-- 10 -->\n      <g transform=\"translate(29.257813 56.748361) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_5\">\n     <g id=\"line2d_15\">\n      <path d=\"M 48.982813 29.398282 \nL 244.282813 29.398282 \n\" clip-path=\"url(#p09f25f1efe)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_16\">\n      <g>\n       <use xlink:href=\"#m49c220cd1c\" x=\"48.982813\" y=\"29.398282\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_9\">\n      <!-- 20 -->\n      <g transform=\"translate(29.257813 33.1975) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-32\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_10\">\n     <!-- f(x) -->\n     <g transform=\"translate(14.798438 85.121094) rotate(-90) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-66\" d=\"M 2375 4863 \nL 2375 4384 \nL 1825 4384 \nQ 1516 4384 1395 4259 \nQ 1275 4134 1275 3809 \nL 1275 3500 \nL 2222 3500 \nL 2222 3053 \nL 1275 3053 \nL 1275 0 \nL 697 0 \nL 697 3053 \nL 147 3053 \nL 147 3500 \nL 697 3500 \nL 697 3744 \nQ 697 4328 969 4595 \nQ 1241 4863 1831 4863 \nL 2375 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-28\" d=\"M 1984 4856 \nQ 1566 4138 1362 3434 \nQ 1159 2731 1159 2009 \nQ 1159 1288 1364 580 \nQ 1569 -128 1984 -844 \nL 1484 -844 \nQ 1016 -109 783 600 \nQ 550 1309 550 2009 \nQ 550 2706 781 3412 \nQ 1013 4119 1484 4856 \nL 1984 4856 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-29\" d=\"M 513 4856 \nL 1013 4856 \nQ 1481 4119 1714 3412 \nQ 1947 2706 1947 2009 \nQ 1947 1309 1714 600 \nQ 1481 -109 1013 -844 \nL 513 -844 \nQ 928 -128 1133 580 \nQ 1338 1288 1338 2009 \nQ 1338 2731 1133 3434 \nQ 928 4138 513 4856 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-66\"/>\n      <use xlink:href=\"#DejaVuSans-28\" transform=\"translate(35.205078 0)\"/>\n      <use xlink:href=\"#DejaVuSans-78\" transform=\"translate(74.21875 0)\"/>\n      <use xlink:href=\"#DejaVuSans-29\" transform=\"translate(133.398438 0)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"line2d_17\">\n    <path d=\"M 57.860085 133.08261 \nL 58.690838 136.111213 \nL 59.39378 137.930609 \nL 60.00087 138.945686 \nL 60.512102 139.399425 \nL 60.927475 139.499151 \nL 61.342855 139.359756 \nL 61.790187 138.945466 \nL 62.301419 138.142486 \nL 62.908503 136.744338 \nL 63.643398 134.431288 \nL 64.506103 130.899791 \nL 65.496614 125.853067 \nL 66.678841 118.622922 \nL 68.148637 108.179673 \nL 70.289416 91.17279 \nL 74.12366 60.620237 \nL 75.72126 49.748813 \nL 77.031292 42.269315 \nL 78.149614 37.103448 \nL 79.108172 33.658291 \nL 79.938925 31.444774 \nL 80.641873 30.145831 \nL 81.248963 29.450775 \nL 81.760194 29.171406 \nL 82.239473 29.161159 \nL 82.718752 29.390933 \nL 83.229984 29.895305 \nL 83.837068 30.832069 \nL 84.540016 32.356455 \nL 85.370763 34.730219 \nL 86.36128 38.299722 \nL 87.543507 43.473686 \nL 88.981344 50.829431 \nL 91.058223 62.749119 \nL 95.020278 85.616324 \nL 96.617875 93.445131 \nL 97.927907 98.815784 \nL 99.046229 102.518437 \nL 100.004787 104.987464 \nL 100.867493 106.628836 \nL 101.602391 107.585666 \nL 102.24143 108.087619 \nL 102.816564 108.27973 \nL 103.359749 108.239502 \nL 103.934886 107.968247 \nL 104.573929 107.400687 \nL 105.308823 106.418643 \nL 106.139573 104.913573 \nL 107.130087 102.625898 \nL 108.312311 99.296822 \nL 109.814056 94.348711 \nL 112.178505 85.660744 \nL 115.213945 74.680985 \nL 116.843498 69.614773 \nL 118.185483 66.138373 \nL 119.335754 63.746936 \nL 120.358221 62.113725 \nL 121.252876 61.076753 \nL 122.083628 60.441983 \nL 122.850477 60.131195 \nL 123.585373 60.072607 \nL 124.32027 60.236654 \nL 125.11907 60.650654 \nL 126.013727 61.379169 \nL 127.03619 62.510036 \nL 128.282318 64.23519 \nL 129.975776 66.991821 \nL 134.544913 74.625563 \nL 135.982753 76.500709 \nL 137.196929 77.739393 \nL 138.283297 78.548754 \nL 139.305762 79.04249 \nL 140.296274 79.275166 \nL 141.286787 79.277766 \nL 142.341203 79.050476 \nL 143.523428 78.555046 \nL 144.961268 77.694798 \nL 147.741093 75.69401 \nL 149.562358 74.539149 \nL 150.840438 73.97691 \nL 151.926807 73.728118 \nL 152.917319 73.719118 \nL 153.875879 73.928512 \nL 154.83444 74.363696 \nL 155.856904 75.080089 \nL 156.943273 76.118854 \nL 158.189401 77.634692 \nL 159.659194 79.795693 \nL 161.704122 83.240193 \nL 164.99518 88.782723 \nL 166.401069 90.699722 \nL 167.519389 91.866072 \nL 168.445997 92.532052 \nL 169.27675 92.864034 \nL 170.011645 92.929294 \nL 170.746543 92.766394 \nL 171.481438 92.365372 \nL 172.248287 91.685916 \nL 173.07904 90.645328 \nL 174.005645 89.113287 \nL 175.060064 86.908213 \nL 176.242288 83.890846 \nL 177.648175 79.647909 \nL 179.405536 73.583277 \nL 185.220805 52.899629 \nL 186.498884 49.476898 \nL 187.52135 47.320254 \nL 188.384053 45.968739 \nL 189.118948 45.189383 \nL 189.757987 44.80807 \nL 190.333125 44.710954 \nL 190.876309 44.839658 \nL 191.451446 45.214086 \nL 192.090486 45.921071 \nL 192.793428 47.054076 \nL 193.592228 48.790287 \nL 194.486887 51.288582 \nL 195.50935 54.826985 \nL 196.691574 59.752175 \nL 198.097461 66.608795 \nL 199.918725 76.688606 \nL 205.54228 108.663564 \nL 206.884264 114.620235 \nL 207.970633 118.510749 \nL 208.897245 121.058001 \nL 209.664092 122.574131 \nL 210.303135 123.401597 \nL 210.846319 123.780539 \nL 211.325598 123.860824 \nL 211.772924 123.71718 \nL 212.252203 123.326509 \nL 212.795388 122.585909 \nL 213.434424 121.309466 \nL 214.169325 119.304817 \nL 215.000078 116.362715 \nL 215.958642 112.113994 \nL 217.076958 106.084201 \nL 218.38699 97.728408 \nL 220.016543 85.794654 \nL 222.572708 65.144383 \nL 225.480334 42.114791 \nL 227.045982 31.427206 \nL 228.292115 24.356688 \nL 229.314578 19.730259 \nL 230.177284 16.760097 \nL 230.912178 14.958637 \nL 231.519268 14.001955 \nL 232.0305 13.581269 \nL 232.445874 13.503656 \nL 232.861247 13.665745 \nL 233.308579 14.11027 \nL 233.819817 14.962145 \nL 234.426901 16.448938 \nL 235.129849 18.808211 \nL 235.385459 19.833134 \nL 235.385459 19.833134 \n\" clip-path=\"url(#p09f25f1efe)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n   </g>\n   <g id=\"line2d_18\">\n    <path d=\"M 178.584824 76.500002 \nL 162.608818 84.826489 \nL 226.496423 34.977034 \nL 235.40554 19.917395 \nL 232.264499 13.508202 \nL 232.373405 13.5 \nL 232.373259 13.5 \nL 232.373265 13.5 \nL 232.373265 13.5 \nL 232.373265 13.5 \nL 232.373265 13.5 \n\" clip-path=\"url(#p09f25f1efe)\" style=\"fill: none; stroke: #ff7f0e; stroke-width: 1.5; stroke-linecap: square\"/>\n    <defs>\n     <path id=\"m9dbc764c15\" d=\"M 0 3 \nC 0.795609 3 1.55874 2.683901 2.12132 2.12132 \nC 2.683901 1.55874 3 0.795609 3 0 \nC 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \nC 1.55874 -2.683901 0.795609 -3 0 -3 \nC -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \nC -2.683901 -1.55874 -3 -0.795609 -3 0 \nC -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \nC -1.55874 2.683901 -0.795609 3 0 3 \nz\n\" style=\"stroke: #ff7f0e\"/>\n    </defs>\n    <g clip-path=\"url(#p09f25f1efe)\">\n     <use xlink:href=\"#m9dbc764c15\" x=\"178.584824\" y=\"76.500002\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m9dbc764c15\" x=\"162.608818\" y=\"84.826489\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m9dbc764c15\" x=\"226.496423\" y=\"34.977034\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m9dbc764c15\" x=\"235.40554\" y=\"19.917395\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m9dbc764c15\" x=\"232.264499\" y=\"13.508202\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m9dbc764c15\" x=\"232.373405\" y=\"13.5\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m9dbc764c15\" x=\"232.373259\" y=\"13.5\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m9dbc764c15\" x=\"232.373265\" y=\"13.5\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m9dbc764c15\" x=\"232.373265\" y=\"13.5\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m9dbc764c15\" x=\"232.373265\" y=\"13.5\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m9dbc764c15\" x=\"232.373265\" y=\"13.5\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n    </g>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 48.982813 145.8 \nL 48.982813 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_4\">\n    <path d=\"M 244.282813 145.8 \nL 244.282813 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_5\">\n    <path d=\"M 48.982812 145.8 \nL 244.282813 145.8 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_6\">\n    <path d=\"M 48.982812 7.2 \nL 244.282813 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n </g>\n <defs>\n  <clipPath id=\"p09f25f1efe\">\n   <rect x=\"48.982813\" y=\"7.2\" width=\"195.3\" height=\"138.6\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "c = torch.tensor(0.15 * np.pi)\n",
    "\n",
    "def f(x):  # Objective function\n",
    "    return x * torch.cos(c * x)\n",
    "\n",
    "def f_grad(x):  # Gradient of the objective function\n",
    "    return torch.cos(c * x) - c * x * torch.sin(c * x)\n",
    "\n",
    "def f_hess(x):  # Hessian of the objective function\n",
    "    return - 2 * c * torch.sin(c * x) - x * c**2 * torch.cos(c * x)\n",
    "\n",
    "r = newton()\n",
    "print(r)\n",
    "show_trace(r, f)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-02-28T02:34:42.109174Z",
     "start_time": "2025-02-28T02:34:41.904297Z"
    }
   },
   "id": "317203c15875856d",
   "execution_count": 13
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "epoch 10, x: tensor(7.2699)\n",
      "[10.0, 7.5, 7.387165069580078, 7.329002380371094, 7.299392223358154, 7.2844414710998535, 7.276927947998047, 7.2731614112854, 7.271275520324707, 7.270331859588623, 7.269859790802002]\n"
     ]
    },
    {
     "data": {
      "text/plain": "<Figure size 350x250 with 1 Axes>",
      "image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"245.120313pt\" height=\"183.35625pt\" viewBox=\"0 0 245.120313 183.35625\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n   <cc:Work>\n    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n    <dc:date>2025-02-28T10:34:42.223964</dc:date>\n    <dc:format>image/svg+xml</dc:format>\n    <dc:creator>\n     <cc:Agent>\n      <dc:title>Matplotlib v3.10.0, https://matplotlib.org/</dc:title>\n     </cc:Agent>\n    </dc:creator>\n   </cc:Work>\n  </rdf:RDF>\n </metadata>\n <defs>\n  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n  <g id=\"patch_1\">\n   <path d=\"M 0 183.35625 \nL 245.120313 183.35625 \nL 245.120313 0 \nL 0 0 \nz\n\" style=\"fill: #ffffff\"/>\n  </g>\n  <g id=\"axes_1\">\n   <g id=\"patch_2\">\n    <path d=\"M 42.620312 145.8 \nL 237.920313 145.8 \nL 237.920313 7.2 \nL 42.620312 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g id=\"matplotlib.axis_1\">\n    <g id=\"xtick_1\">\n     <g id=\"line2d_1\">\n      <path d=\"M 51.497585 145.8 \nL 51.497585 7.2 \n\" clip-path=\"url(#pa4685bb284)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_2\">\n      <defs>\n       <path id=\"m5e8cb3c0c6\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m5e8cb3c0c6\" x=\"51.497585\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_1\">\n      <!-- −10 -->\n      <g transform=\"translate(40.945241 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-2212\" d=\"M 678 2272 \nL 4684 2272 \nL 4684 1741 \nL 678 1741 \nL 678 2272 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-31\" transform=\"translate(83.789062 0)\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(147.412109 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_2\">\n     <g id=\"line2d_3\">\n      <path d=\"M 95.883949 145.8 \nL 95.883949 7.2 \n\" clip-path=\"url(#pa4685bb284)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_4\">\n      <g>\n       <use xlink:href=\"#m5e8cb3c0c6\" x=\"95.883949\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_2\">\n      <!-- −5 -->\n      <g transform=\"translate(88.512855 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \nL 3169 4666 \nL 3169 4134 \nL 1269 4134 \nL 1269 2991 \nQ 1406 3038 1543 3061 \nQ 1681 3084 1819 3084 \nQ 2600 3084 3056 2656 \nQ 3513 2228 3513 1497 \nQ 3513 744 3044 326 \nQ 2575 -91 1722 -91 \nQ 1428 -91 1123 -41 \nQ 819 9 494 109 \nL 494 744 \nQ 775 591 1075 516 \nQ 1375 441 1709 441 \nQ 2250 441 2565 725 \nQ 2881 1009 2881 1497 \nQ 2881 1984 2565 2268 \nQ 2250 2553 1709 2553 \nQ 1456 2553 1204 2497 \nQ 953 2441 691 2322 \nL 691 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(83.789062 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_3\">\n     <g id=\"line2d_5\">\n      <path d=\"M 140.270312 145.8 \nL 140.270312 7.2 \n\" clip-path=\"url(#pa4685bb284)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_6\">\n      <g>\n       <use xlink:href=\"#m5e8cb3c0c6\" x=\"140.270312\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_3\">\n      <!-- 0 -->\n      <g transform=\"translate(137.089062 160.398438) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_4\">\n     <g id=\"line2d_7\">\n      <path d=\"M 184.656676 145.8 \nL 184.656676 7.2 \n\" clip-path=\"url(#pa4685bb284)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_8\">\n      <g>\n       <use xlink:href=\"#m5e8cb3c0c6\" x=\"184.656676\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_4\">\n      <!-- 5 -->\n      <g transform=\"translate(181.475426 160.398438) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-35\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_5\">\n     <g id=\"line2d_9\">\n      <path d=\"M 229.04304 145.8 \nL 229.04304 7.2 \n\" clip-path=\"url(#pa4685bb284)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_10\">\n      <g>\n       <use xlink:href=\"#m5e8cb3c0c6\" x=\"229.04304\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_5\">\n      <!-- 10 -->\n      <g transform=\"translate(222.68054 160.398438) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_6\">\n     <!-- x -->\n     <g transform=\"translate(137.310937 174.076563) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-78\" d=\"M 3513 3500 \nL 2247 1797 \nL 3578 0 \nL 2900 0 \nL 1881 1375 \nL 863 0 \nL 184 0 \nL 1544 1831 \nL 300 3500 \nL 978 3500 \nL 1906 2253 \nL 2834 3500 \nL 3513 3500 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-78\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_2\">\n    <g id=\"ytick_1\">\n     <g id=\"line2d_11\">\n      <path d=\"M 42.620312 121.640967 \nL 237.920313 121.640967 \n\" clip-path=\"url(#pa4685bb284)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_12\">\n      <defs>\n       <path id=\"mc2fa834249\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#mc2fa834249\" x=\"42.620312\" y=\"121.640967\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_7\">\n      <!-- −5 -->\n      <g transform=\"translate(20.878125 125.440185) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-2212\"/>\n       <use xlink:href=\"#DejaVuSans-35\" transform=\"translate(83.789062 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_2\">\n     <g id=\"line2d_13\">\n      <path d=\"M 42.620312 76.5 \nL 237.920313 76.5 \n\" clip-path=\"url(#pa4685bb284)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_14\">\n      <g>\n       <use xlink:href=\"#mc2fa834249\" x=\"42.620312\" y=\"76.5\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_8\">\n      <!-- 0 -->\n      <g transform=\"translate(29.257812 80.299219) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_3\">\n     <g id=\"line2d_15\">\n      <path d=\"M 42.620312 31.359033 \nL 237.920313 31.359033 \n\" clip-path=\"url(#pa4685bb284)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n     </g>\n     <g id=\"line2d_16\">\n      <g>\n       <use xlink:href=\"#mc2fa834249\" x=\"42.620312\" y=\"31.359033\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_9\">\n      <!-- 5 -->\n      <g transform=\"translate(29.257812 35.158252) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-35\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_10\">\n     <!-- f(x) -->\n     <g transform=\"translate(14.798437 85.121094) rotate(-90) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-66\" d=\"M 2375 4863 \nL 2375 4384 \nL 1825 4384 \nQ 1516 4384 1395 4259 \nQ 1275 4134 1275 3809 \nL 1275 3500 \nL 2222 3500 \nL 2222 3053 \nL 1275 3053 \nL 1275 0 \nL 697 0 \nL 697 3053 \nL 147 3053 \nL 147 3500 \nL 697 3500 \nL 697 3744 \nQ 697 4328 969 4595 \nQ 1241 4863 1831 4863 \nL 2375 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-28\" d=\"M 1984 4856 \nQ 1566 4138 1362 3434 \nQ 1159 2731 1159 2009 \nQ 1159 1288 1364 580 \nQ 1569 -128 1984 -844 \nL 1484 -844 \nQ 1016 -109 783 600 \nQ 550 1309 550 2009 \nQ 550 2706 781 3412 \nQ 1013 4119 1484 4856 \nL 1984 4856 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-29\" d=\"M 513 4856 \nL 1013 4856 \nQ 1481 4119 1714 3412 \nQ 1947 2706 1947 2009 \nQ 1947 1309 1714 600 \nQ 1481 -109 1013 -844 \nL 513 -844 \nQ 928 -128 1133 580 \nQ 1338 1288 1338 2009 \nQ 1338 2731 1133 3434 \nQ 928 4138 513 4856 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-66\"/>\n      <use xlink:href=\"#DejaVuSans-28\" transform=\"translate(35.205078 0)\"/>\n      <use xlink:href=\"#DejaVuSans-78\" transform=\"translate(74.21875 0)\"/>\n      <use xlink:href=\"#DejaVuSans-29\" transform=\"translate(133.398438 0)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"line2d_17\">\n    <path d=\"M 51.497585 76.500001 \nL 54.515859 62.586451 \nL 57.090268 51.752961 \nL 59.309586 43.325861 \nL 61.351355 36.406086 \nL 63.215583 30.83764 \nL 64.991044 26.23239 \nL 66.588956 22.687908 \nL 68.098084 19.871522 \nL 69.518451 17.695347 \nL 70.761268 16.168286 \nL 72.004085 14.990564 \nL 73.158131 14.20593 \nL 74.223403 13.741354 \nL 75.288675 13.521051 \nL 76.353951 13.539197 \nL 77.419222 13.789079 \nL 78.484494 14.263148 \nL 79.63854 15.020002 \nL 80.881362 16.105041 \nL 82.212949 17.560774 \nL 83.722086 19.551486 \nL 85.408769 22.166601 \nL 87.272996 25.480233 \nL 89.40354 29.726556 \nL 91.977948 35.366172 \nL 95.528858 43.724429 \nL 103.163314 61.839574 \nL 106.004039 67.93953 \nL 108.400904 72.589371 \nL 110.53145 76.262462 \nL 112.484448 79.203521 \nL 114.259903 81.497532 \nL 115.946585 83.326808 \nL 117.544495 84.737454 \nL 119.05363 85.779104 \nL 120.473994 86.502463 \nL 121.894359 86.980124 \nL 123.314722 87.218052 \nL 124.735085 87.224602 \nL 126.155449 87.010408 \nL 127.664585 86.55531 \nL 129.262494 85.837474 \nL 131.037949 84.784116 \nL 132.990949 83.357255 \nL 135.29904 81.380765 \nL 138.317313 78.475538 \nL 145.951767 70.98275 \nL 148.259858 69.094507 \nL 150.212858 67.764372 \nL 151.988312 66.814949 \nL 153.586222 66.202363 \nL 155.095359 65.855652 \nL 156.515722 65.750362 \nL 157.936085 65.871412 \nL 159.356448 66.228309 \nL 160.776812 66.828229 \nL 162.197176 67.675905 \nL 163.706313 68.850493 \nL 165.215448 70.306795 \nL 166.813358 72.151568 \nL 168.588811 74.556208 \nL 170.453039 77.464178 \nL 172.494811 81.066691 \nL 174.802902 85.607401 \nL 177.466086 91.359601 \nL 180.83945 99.206191 \nL 190.071814 120.997816 \nL 192.557452 126.154107 \nL 194.687995 130.082447 \nL 196.552223 133.061892 \nL 198.150131 135.22328 \nL 199.659268 136.894963 \nL 200.990859 138.046958 \nL 202.233676 138.831093 \nL 203.387723 139.294721 \nL 204.452994 139.487343 \nL 205.51827 139.446476 \nL 206.583542 139.165611 \nL 207.648814 138.639155 \nL 208.714086 137.862434 \nL 209.868132 136.734267 \nL 211.110949 135.182124 \nL 212.442541 133.128478 \nL 213.862903 130.492079 \nL 215.37204 127.189752 \nL 216.969952 123.138737 \nL 218.745405 117.986217 \nL 220.609632 111.867898 \nL 222.651401 104.384167 \nL 224.959502 95.024237 \nL 227.533903 83.601979 \nL 228.954265 76.925033 \nL 228.954265 76.925033 \n\" clip-path=\"url(#pa4685bb284)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n   </g>\n   <g id=\"line2d_18\">\n    <path d=\"M 229.04304 76.499999 \nL 206.849858 139.05722 \nL 205.848192 139.385423 \nL 205.331865 139.470774 \nL 205.069008 139.492617 \nL 204.936286 139.498145 \nL 204.869587 139.499535 \nL 204.83615 139.499884 \nL 204.819408 139.499974 \nL 204.811031 139.499996 \nL 204.806841 139.5 \n\" clip-path=\"url(#pa4685bb284)\" style=\"fill: none; stroke: #ff7f0e; stroke-width: 1.5; stroke-linecap: square\"/>\n    <defs>\n     <path id=\"mb4e6886cad\" d=\"M 0 3 \nC 0.795609 3 1.55874 2.683901 2.12132 2.12132 \nC 2.683901 1.55874 3 0.795609 3 0 \nC 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \nC 1.55874 -2.683901 0.795609 -3 0 -3 \nC -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \nC -2.683901 -1.55874 -3 -0.795609 -3 0 \nC -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \nC -1.55874 2.683901 -0.795609 3 0 3 \nz\n\" style=\"stroke: #ff7f0e\"/>\n    </defs>\n    <g clip-path=\"url(#pa4685bb284)\">\n     <use xlink:href=\"#mb4e6886cad\" x=\"229.04304\" y=\"76.499999\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mb4e6886cad\" x=\"206.849858\" y=\"139.05722\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mb4e6886cad\" x=\"205.848192\" y=\"139.385423\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mb4e6886cad\" x=\"205.331865\" y=\"139.470774\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mb4e6886cad\" x=\"205.069008\" y=\"139.492617\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mb4e6886cad\" x=\"204.936286\" y=\"139.498145\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mb4e6886cad\" x=\"204.869587\" y=\"139.499535\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mb4e6886cad\" x=\"204.83615\" y=\"139.499884\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mb4e6886cad\" x=\"204.819408\" y=\"139.499974\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mb4e6886cad\" x=\"204.811031\" y=\"139.499996\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#mb4e6886cad\" x=\"204.806841\" y=\"139.5\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n    </g>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 42.620312 145.8 \nL 42.620312 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_4\">\n    <path d=\"M 237.920313 145.8 \nL 237.920313 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_5\">\n    <path d=\"M 42.620312 145.8 \nL 237.920313 145.8 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_6\">\n    <path d=\"M 42.620312 7.2 \nL 237.920313 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n </g>\n <defs>\n  <clipPath id=\"pa4685bb284\">\n   <rect x=\"42.620312\" y=\"7.2\" width=\"195.3\" height=\"138.6\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "r = newton(0.5)\n",
    "print(r)\n",
    "show_trace(r, f)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-02-28T02:34:42.252426Z",
     "start_time": "2025-02-28T02:34:42.110975Z"
    }
   },
   "id": "f2a6f75075718e02",
   "execution_count": 14
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-02-28T02:34:42.256813Z",
     "start_time": "2025-02-28T02:34:42.253986Z"
    }
   },
   "id": "c2ee657d33e4a0b3",
   "execution_count": 14
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
